30Apr/090
RegEx to id comma-space(s) or space(s) delimited text
I'm not all that great at RegEx, but I needed split a line of text on commas followed by spaces and/or by spaces (including tabs). 30 minutes later after swearing and sweating with iPython, I produced the following little expression. Who needs the CSV module?
re.compile(',(?:\s*)|\s*')
Example Usage:
line = 'one, two three four, five' pattern = re.compile(',(?:\s*)|\s*') line.pattern(split) >>> ['one', 'two', 'three', 'four', 'five']