re module non-greedy matches broken

John Ridley ojokimu at yahoo.co.uk
Mon Apr 4 13:53:38 EDT 2005


--- lothar <lothar at ultimathule.nul> wrote:
> how then, do i specify a non-greedy regex
>   <1st-pat><not-1st-pat>*?<follow-pat>
> 
> that is, such that non-greedy part <not-1st-pat>*?
> excludes a match of <1st-pat>
> 
> in other words, how do i write regexes for my examples?
 
Not sure if I completely understand your explanation, but does this get
any closer to what your looking for?

>>> vwre = re.compile("V[^V]*?W")
>>> newdoc = "V1WVVV2WWW"
>>> re.findall(vwre, newdoc)
['V1W', 'V2W']

That is: <pat1>, then <not-pat1> as few times as possible, then <pat2>


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 



More information about the Python-list mailing list