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.
精彩评论