Greg
Greg

Reputation: 47124

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

Upvotes: 3

Views: 2917

Answers (2)

Dov Wasserman
Dov Wasserman

Reputation: 2682

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/

Upvotes: 4

John Nilsson
John Nilsson

Reputation: 17307

The feature you'r looking for is look ahead patterns

665(?!.*\.pdf)

Upvotes: 2

Related Questions