开发者

Find complete word in text using Regex

I am looking for a regex that would indicate if there is a certain complete word in a text, for example for the word "cto":

  • "i am a cto" - true
  • "i am a cto/developer" - true
  • 开发者_如何学Go"cto" - true
  • "i am a cto_developer" - true
  • "ctools" - false

I want the word to be case insensitive. Any thoughts?


(?<=^|[^a-zA-Z0-9])<word>(?=$|[^a-zA-Z0-9])

Finds instances of <word> that are only preceded or succeeded by beginning or end of line/string or characters a-z or numbers 0-9. Example from RegexHero.

It would help if we knew what language this is in.


You could either write an expression considering all the possibilities or use the \b anchor like \bmyWord\b and consider the _ a lost case because it's handled as part of the word so the "i am a cto_developer" will also return false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜