1

I have the following go code:

s := `prefix<b>Group ID:</b><br/>
G123<br/>temporary<br/>suffix`

re := regexp.MustCompile(`(?s)(.*)<b>Group ID:</b><br/>(.*)<br/>(.*)`)

m := re.FindAllStringSubmatch(s, -1)
fmt.Println(m[0][2])

playground link: https://play.golang.org/p/hz2kg7Pe2Z

The above program prints \nG123<br/>temporary because the last/second <br/> after the pattern is matched, as per the regex. Is there a way to get the first <br/> to be matched so that the output will be, just: G123. In addition to the first br match, the newline/whitespace in the beginning should also be stripped. Any suggestions ?

Sankar
  • 6,192
  • 12
  • 65
  • 89

0 Answers0