Non greedy regex

tibetan.houdini at gmail.com tibetan.houdini at gmail.com
Thu Dec 14 09:45:46 EST 2006


Can someone please explain why these expressions both produce the same
result? Surely this means that non-greedy regex does not work?

print re.sub( 'a.*b', '', 'ababc' )

gives: 'c'

Understandable. But

print re.sub( 'a.*?b', '', 'ababc' )

gives: 'c'

NOT, understandable. Surely the answer should be: 'abc'




More information about the Python-list mailing list