Reputation: 12913
I have lines like this:
example.com/p/stuff/...
example.com/page/thing/...
example.com/page/stuff/...
example.com/page/other-stuff/...
etc
where the dots represent continuing URL paths. I want to select URLs that contain /page/
and are NOT followed by thing/
. So from the above list we would select:
example.com/page/stuff/...
example.com/page/other-stuff/...
Upvotes: 2
Views: 51
Reputation: 18744
.*?\/page\/[^(thing)].*
this is the regex for matching a string which has /page/
not followed by thing
adding the lazy evalation is suggested because you advance a char at the time, better performance!
Upvotes: 1
Reputation: 92854
Use the following regex pattern:
.*?\/page\/(?!thing\/).*
https://regex101.com/r/19wh1w/2
(?!thing\/)
- negative lookahead assertion ensures that page/
section is not followed by thing/
Upvotes: 1
Reputation: 6421
You need to use negative lookahead:
example\.com\/page\/(?!thing\/).*
Upvotes: 1