I want to get the index of all tags inside brackets using regex package.
str := "[tag=blue]Hello [tag2=red,tag3=blue]Good"
rg := regexp.MustCompile(`(?:^|\W)\[([\w-]+)=([\w-]+)\]`)
rgi := fmtRegex.FindAllStringIndex(str, -1)
fmt.Println(rgi)
// Want index for:
// [tag=blue], [tag2=red,tag3=blue]
The regex needs to return indexes for [tag=blue], [tag2=red,tag3=blue]
but it only returns [tag=blue]
.
How do I fix this regex (?:^|\W)\[([\w-]+)=([\w-]+)\]
so that I can also match the comman when there is more than one tags in the brackets