Isn't re.findall supposed to find all?

June Kim junaftnoon at
Sat Nov 11 00:31:57 CET 2000

Well, I forgot the old rule "Longest match possible."
It worked perfectly with this:
>>> z
>>> 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


More information about the Python-list mailing list