Home > Back-end >  Regex for contains pair of words
Regex for contains pair of words

Time:12-13

I want to find if sentence has a pair of word, for example

word = "not interested"

and should match "I am not interested" and "I am not also interested"

even though there is a extra word between not and interested I want to match it how can I express this as regular expression?

CodePudding user response:

Try:

not\s (?:\S \s )?interested

Regex demo.


not - match not

\s - match any amount of spaces

(?:\S \s )? - optional, match any anoumt of non-spaces spaces (a word)

interested - match interested

  • Related