我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何使用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.

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

regexp.MatchString("\\bword\\b", test)

近期文章

  • 当A的方法在Go中返回B时模拟对象A和B
  • 在golang中执行echo和openssl命令
  • 类型foo struct和类型foo [] struct的区别
  • Golang调试器未运行
  • 是否可以将可变参数与标志包用法结合使用? [关闭]
  • 致命错误:所有goroutine都在睡着-死锁! 当通道未缓冲时
  • 登录Golang测试用例[重复]
  • golang供应商路径找不到包
  • 如何同时打印和扫描
  • 在Golang中使用现有接口时如何添加更多功能?
  • 从emersion / go-imap获取原始消息
  • 未使用Golang设置Cookie
  • 多个Http.Get随机挂起
  • switch语句中的变量范围问题
  • 没有嵌套初始化的golang字段继承
  • 将空接口转换为Golang中的等效类型
  • 在函数中初始化通道导致执行例程死锁
  • 为什么在“热身”后解组JSON的速度更快?
  • 即使使用url编码(添加标题),Axios和fetch也会在Golang中提供空映射
  • Golang中的嵌套循环

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华