a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
phlip2005 at gmail.com
Thu Nov 25 05:46:18 CET 2010
I need to turn a human-readable list into a list():
print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
That currently returns ('c',). I'm trying to match "any word \w+
followed by a comma, or a final word preceded by and."
The match returns 'a, bbb, and c', but the groups return ('bbb', 'c').
What do I type for .groups() to also get the 'a'?
Please go easy on me (and no RTFM!), because I have only been using
regular expressions for about 20 years...
More information about the Python-list