Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find lines containing sequence but not containing a different sequence

How do I write a regular expression to find all lines containing 665 and not having .pdf

I can't seem to find how to do not in regex. This is for Notepad++ syntax if it matters.

Thanks

like image 357
Greg Avatar asked Dec 12 '25 04:12

Greg


2 Answers

If .pdf will only occur after 665, the negative lookahead assertion 665(?!.*\.pdf) should work fine. Otherwise, I prefer to use two regexs, one to match, one to fail. In Perl syntax that would be:

/665/ && !/\.pdf/
like image 186
Dov Wasserman Avatar answered Dec 14 '25 18:12

Dov Wasserman


The feature you'r looking for is look ahead patterns

665(?!.*\.pdf)
like image 30
John Nilsson Avatar answered Dec 14 '25 16:12

John Nilsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!