我正在使用函数 regexp.matchString() 将正则表达式模式与我的字符串匹配。我必须使用词边界才能找到完全匹配。例如,我想匹配“计算”而不是“计算机”。问题是我的字符串将同时具有“计算”和“计算机”。所以我想使用词边界。我尝试在几个在线 go-regex 测试器中使用 \b 并且它起作用了。但是, \b 似乎不适用于 regexp.matchString() 函数。有谁知道 \b 是否有替代品?或者我怎样才能得到预期的结果?我的代码
package main
import "fmt"
import "regexp"
func main() {
fmt.Println("Hello, playground")
brandName := "home;compute furniture;computer"
filterVal := "(?i)compute\b"
regexMatch, _ := regexp.MatchString(filterVal, brandName)
fmt.Println(regexMatch)
}
当我使用 \b 时,此函数返回 false。请帮忙
守着一只汪
相关分类