I am trying to parse the following string:
`%%% First %%% part 1 %%% Second %%% part2`
This goes on and on into an unknown number of parts...e.g. Third, Fourth, Another, Car, Airplane, etc... all are separated by "%%% Something %%%"
I have:
package main
import (
"fmt"
"regexp"
)
func main() {
reg:= regexp.MustCompile(`(?P<part>%%% .* %%%)+`)
match := reg.FindStringSubmatch(`%%% First %%% part 1 %%% Second %%% part2`)
if len(match) == 0 {
fmt.Println("not found")
}
for i, g := range reg.SubexpNames() {
if i == 0 || g == "" {
continue
}
switch g {
case "part":
fmt.Println("part:", match[i])
default:
fmt.Printf("what group %q", g)
}
}
}
Gives:
part: %%% First %%% part 1 %%% Second %%%
How do I get output so that it prints like the following where part 1 and part 2 are separate matching groups? I would like to ignore "First" entirely and just focus on "Second":
part 2