I want a regex expression that extract values seperated by commas.
Sample input: "John Doe, Jack, , Henry,Harry,,Rob"
Expected output:
John Doe
Jack
Henry
Harry
Rob
I tried [\w ]
but blank values and extra spaces are getting included
CodePudding user response:
Given:
>>> s="John Doe, Jack, , Henry,Harry,,Rob"
You can do:
>>> [e for e in re.split(r'\s*,\s*',s) if e]
['John Doe', 'Jack', 'Henry', 'Harry', 'Rob']