1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
感謝提供的評(píng)論,我得到的是:
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
p := []string{}
p = append(p, "engineer")
p = append(p, "doctor")
p = append(p, "chemical (permit)")
skills := strings.Join(p, "|")
fmt.Println(skills)
re := regexp.MustCompile(`(?i)` + skills)
matches := re.FindAllString("I'm an engineer not a doctor who is getting chemical permits", -1)
fmt.Println(matches, len(matches))
for i, j := range matches {
fmt.Println(i, j)
}
}
輸出是:
engineer|doctor|chemical (permit)
[engineer doctor chemical permit] 3
0 engineer
1 doctor
2 chemical permit
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)