Isn't re.findall supposed to find all?

June Kim junaftnoon at nospamplzyahoo.com
Fri Nov 10 18:31:57 EST 2000


Well, I forgot the old rule "Longest match possible."
It worked perfectly with this:
>>> z
'[abcdefrdofhd]kdeioslkdfj[sdkfj]'
>>> p=re.compile('\[[^\[]*\]')
>>> re.findall(p,z)
['[abcdefrdofhd]', '[sdkfj]']

But another problem emerged. What if the brackets were
longer than one character? for example:
z='this is yet another start of a sting end but never start an end'

opening bracket : "start"
closing bracket : "end"

What I want to get is,

re.findall(p,z) == ['[start of a string end]','[start an end]']

How should I render the regular expression?

Thanks in advance

---------
June




More information about the Python-list mailing list