我有下面的代码,我希望用户输入一些关键字,然后从给定字符串中找到这些单词中存在的内容,但生成的切片是长度等于要检查的文本的空切片 playgroundmatches
package main
import (
"fmt"
"regexp"
)
func main() {
p := []string{}
p = append(p, "engineer")
p = append(p, "doctor")
var skills string
for _, z := range p {
skills += `|` + z
}
fmt.Println(skills)
re := regexp.MustCompile(`(?i)` + skills)
matches := re.FindAllString("I'm an engineer not a doctor", -1)
fmt.Println(matches)
for i, j := range matches {
fmt.Println(i, j)
}
}
POPMUISE
相关分类