python
Java/Python inverse regex
By dmytro - Posted on December 15th, 2009
Very simple but not very obvious inverse java/python regex:
^(.(?!(some text)))*$
So "String with some text inside" will give us:
>>> re.compile("^(.(?!(some text)))*$")
>>> r = regex.search(string)
# No match was found:
>>> rAnd "String without":
>>> re.compile("^(.(?!(some text)))*$")
>>> r = regex.search(string)
>>> r
<_sre.SRE_Match object at 0xc70014791f56cff8>
>>> regex.match(string)
<_sre.SRE_Match object at 0xc70014791f56ce00>Tada :)
Links:
http://www.pythonregex.com/ - online python regex test tool
