Find all strings not preceeded by another, with anything in between in notepad++

89 Views Asked by At

I know using a simple negative lookbehind

#(?<!first word)\r\nsecond word#s

This will not find second word in

some text
first word
second word
some text

and matches as expected in

some text
second word
some text

It also matches here, but it should not

some text
first word
any other text
second word
some text

How do I need to modify my regular expression to meet the requirements ?

I tried #(?<!first word).*second word#s, but it always matches.

I need this to search through many files in notepad++

1

There are 1 best solutions below

2
On

Your first regexp is matching 3rd example as if it is looking a string that is not first word and which has a second word as a next string.

The last regexp would match everything because of .* which is matching everything.

I'm suggesting to add a .* in negative lookbehind.

I don't know which editor you are using, so please correct if it's not corresponding to your's regexp syntax.

I would search a maximal long string which has not first word to be proceeded by second word like this

^(?!.*first word.*)\r\nsecond word

I hope it will work.

Good luck!