re module non-greedy matches broken
John Ridley
ojokimu at yahoo.co.uk
Mon Apr 4 17:57:03 EDT 2005
--- lothar <lothar at ultimathule.nul> wrote:
> no - in the non-greedy regex
> <1st-pat><not-1st-pat>*?<follow-pat>
>
> <1st-pat>, <not-1st-pat> and <follow-pat> are arbitrarily complex
> patterns.
Could you post some real-world examples of the problems you are trying
to deal with, please? Trying to come up with general solutions for
arbitrarily complex patterns is a bit to hard for me :)
> with character classes and negative character classes you do not need
> non-greediness anyway.
And yet in the simple case you supplied it does make a difference:
>>> newdoc = "V1WVVV2WWW"
>>> vwre = re.compile("V[^V]*W")
['V1W', 'V2WWW']
>>> vwre = re.compile("V[^V]*?W")
>>> vwre.findall(newdoc)
['V1W', 'V2W']
Not exactly rocket-science, but it gets the job done...
John Ridley
Send instant messages to your online friends http://uk.messenger.yahoo.com
More information about the Python-list
mailing list