Regex: match everything but a specific pattern

ghz 1years ago ⋅ 5930 views

Question

I need a regular expression able to match everything but a string starting with a specific pattern (specifically index.php and what follows, like index.php?id=2342343).


Answer

You could use a negative lookahead from the start, e.g., ^(?!foo).*$ shouldn't match anything starting with foo.