如何在regexp.MatchString()中使用单词边界(\ b)

pri*_*esh 1 regex go word-boundary

我正在使用函数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)
}
Run Code Online (Sandbox Code Playgroud)

当我使用\ b时,此函数返回false。请帮忙

Ain*_*r-G 5

双引号经常吞下\。始终将原始字符串与regexp,SQL等一起使用。

filterVal := `(?i)compute\b`
Run Code Online (Sandbox Code Playgroud)

游乐场:http : //play.golang.org/p/ePzZf5uLtw