shadyyx
shadyyx

Reputation: 16055

RegEx - find all occurrences of a word and exclude certain words that contain it

searching all over couldn't find a solution and also am breaking my head with this for a while already.

I want to search for all occurrences (words not sentences containing) of word end but exclude certain words from being found - that I want to specify myself.

For example, I am interested in all possible combinations of (should match):

but I want to exclude all these words for example (should not match):

while not selecting the whole lines, only the matching words.

The closest I could get is this regex: (?!extend|appendTo|render|renderGrid)(\b.*end.*\b) but this selects the whole lines and more-over doesn't work in Search in files in IntelliJ IDEs which is frustrating.

Anybody willing to improve and make it working in Search in files in IDEs?

Upvotes: 1

Views: 492

Answers (1)

The fourth bird
The fourth bird

Reputation: 163457

You could match 0+ times a non whitespace char \S* at both ends or use a character class [\w-]* and specify what you would allow to match.

You might omit the capturing group and get the matches only.

(?!extend|append|render|renderGrid)\b\S*end\S*\b

Regex demo

Upvotes: 2

Related Questions