求一个逻辑代码

hellsam · · 1770 次点击
更多评论
```go var str = `aaaaa(tp id = "1")中国(/tp)嗯(tp id = "2")香港(/tp)哦哦哦(tp id = "3")CHINA(/tp)。。。地方` func TestRegex(t *testing.T) { reg, err := regexp.Compile("[(]tp id = \"\\d+\"[)]\\S+[(]/tp[)]") if err != nil { t.Fatal(err) } subs := reg.FindAllStringSubmatch(str, -1) for _, sub := range subs { t.Log(sub[0]) } } ``` 结果: ```go === RUN TestRegex d_test.go:19: (tp id = "1")中国(/tp) d_test.go:19: (tp id = "2")香港(/tp) d_test.go:19: (tp id = "3")CHINA(/tp) --- PASS: TestRegex (0.00s) ```
#1