Home > Blockchain >  Need to get Particular word using java Regex
Need to get Particular word using java Regex

Time:10-17

I want to get one particular word using regex in java. thanks

in the below paragraph, I need to find the network interface name

resource "azurerm_network_interface" "nic_LinuxVMCent-nhi" {
name = "nic_LinuxVMCent-nhi"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
ip_configuration {
name = "pubIP_LinuxVMCent-nhi"
subnet_id = azurerm_subnet.sub_wind12VM-PtN.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.pubIP_LinuxVMCent-nhi.id
}
}
data "azurerm_snapshot" "snapLinuxVMCent-nhi" {
name = "CentOS76New-0"
resource_group_name = "SaaSworkloadsnaps"
}

Expected Result Ex:

nic_LinuxVMCent-nhi

CodePudding user response:

This is a multi-line bit of text. However, there appears to be a line which you could recognise with a regex:

resource "azurerm_network_interface" "nic_LinuxVMCent-nhi" {

So the regex for that would be ^resource "azurerm_network_interface" "([^"] )" {$ - see https://regexr.com/67ldb

You can use Matcher.match to see if the any line matches this expression and if it does then matcher.group(1) will be the value you're looking for.

  • Related