Ran
Ran

Reputation: 3523

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 want the word to be case insensitive. Any thoughts?

Upvotes: 0

Views: 2081

Answers (2)

Håvard
Håvard

Reputation: 10080

(?<=^|[^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.

Upvotes: 4

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.

Upvotes: 0

Related Questions