re.findall documentation wrong?
Skip Montanaro
skip at pobox.com
Fri May 23 18:10:59 EDT 2003
Antti> However, re.findall() or re.compile(<regexp>).findall() refuse to
Antti> return lists of anything but strings.
Works for me:
>>> re.findall("[^ =]+=[^ ]*", "key=val abc=def red=blue black=")
['key=val', 'abc=def', 'red=blue', 'black=']
>>> re.findall("(?P<key>[^ =]+)=(?P<val>[^ ]*) *", "key=val abc=def red=blue black=")
[('key', 'val'), ('abc', 'def'), ('red', 'blue'), ('black', '')]
To get a list of tuples of strings you need to define groups in your regular
expression. Otherwise you get a list of strings.
Skip
More information about the Python-list
mailing list