I have the following text file I would like to parse out to get the individual fields:
host_group_web = ( )
host_group_lbnorth = ( lba050 lbhou002 lblon003 )
The fields that I would like to extract are in bold
- host_group_web = ( )
- host_group_lbnorth = ( lba505 lbhou002 lblon003 )
host_group_web has no items in between the ( ), so that portion would be ignored
I've named the first group as nodegroup and the items in between the () as nodes
I am reading the file line by line, and storing the results for further processing.
In Golang, This is the snippet of Regex I am using:
hostGroupLine := "host_group_lbnorth = ( lba050 lbhou002 lblon003 )"
hostGroupExp := regexp.MustCompile(`host_group_(?P<nodegroup>[[:alnum:]]+)\s*=\s*\(\s*(?P<nodes>[[:alnum:]]+\s*)`)
hostGroupMatch := hostGroupExp.FindStringSubmatch(hostGroupLine)
for i, name := range hostGroupExp.SubexpNames() {
if i != 0 {
fmt.Println("GroupName:", name, "GroupMatch:", hostGroupMatch[i])
}
}
I get the following output, which is missing the rest of the matches for the nodes named group.
GroupName: nodegroup GroupMatch: lbnorth
GroupName: nodes GroupMatch: lba050
The Snippet in Golang Playground
My question is, how do I get a Regex in Golang that would match the nodegroup and all the nodes that maybe in the line, e.g lba050 lbhou002 lblon003. The amount of nodes will vary, from 0 - as many.