doulin6088 2018-12-20 15:44
浏览 1046
已采纳

如何使用Golang正则表达式查找完全匹配的单词?

I am trying to find words in a large text file. The MatchString method doesn't inherently look for exact word match, rather it looks for the pattern as it should.

How does one check for exact word match using regexp package in Golang? I have tried some regex'es i found on SO, but it didn't work.

  • 写回答

1条回答 默认 最新

  • dongqiao6445 2018-12-20 16:22
    关注

    Use the zero-length word boundry sequence \b: https://play.golang.org/p/-f0KEKb2EbF

    regexp.MatchString("\\bword\\b", test)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了