This works great for me. Perhaps you are using it incorrectly? Be sure to use re.search instead of re.match :
>>> import re >>> s = 'somestring.asp?1=123' >>> re.search(r"(?<!(asp|php|jsp))\?.*", s) >>> s = 'somestring.xml?1=123' >>> re.search(r"(?<!(asp|php|jsp))\?.*", s) <_sre.SRE_Match object at 0x0000000002DCB098>
This is how your template should behave. As mentioned in glglgl, you can get a match if you assign this Match object to a variable (say m ) and then call m.group() . This gives ?1=123 .
By the way, you can leave the inner brackets. This pattern is equivalent to:
(?<!asp|php|jsp)\?.*
Martin ender
source share