Hi to all, I need a regex able to match everything but a string starting with a specific pattern (specifically index.php and what follows, like index.php?id=2342343)
Any help appreciated. Thanks
Hi to all, I need a regex able to match everything but a string starting with a specific pattern (specifically index.php and what follows, like index.php?id=2342343)
Any help appreciated. Thanks
grep -v in shell
!~ in perl
Please add more in other languages - I marked this as Community Wiki.
Not a regexp expert, but I think you could use a negative lookahead from the start, e.g. ^(?!foo).*$
shouldn't match anything starting with foo
.
In python:
>>> import re
>>> p='^(?!index\.php\?[0-9]+).*$'
>>> s1='index.php?12345'
>>> re.match(p,s1)
>>> s2='index.html?12345'
>>> re.match(p,s2)
<_sre.SRE_Match object at 0xb7d65fa8>
How about not using regex:
// In PHP
0 !== strpos($string, 'index.php')