Java/Python inverse regex

Tagged:  

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:
>>> r

And "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
http://docs.python.org/library/re.html - official python docs

Your rating: None Average: 5 (3 votes)