What would be the regex for separating a string into a list of items based on comas and/or white spaces?
Example:
"item1, item2 item3 item4 , item5"
Result: ["item1", "item2", "item3", "item4", "item5"]
What would be the regex for separating a string into a list of items based on comas and/or white spaces?
Example:
"item1, item2 item3 item4 , item5"
Result: ["item1", "item2", "item3", "item4", "item5"]
You can use the following regex [,\s]+
to find your delimiters.
Here is an example on python:
import re
text = "item1, item2 item3 item4 , item5"
result = re.split(r'[,\s]+', text)
This code return the following output:
['item1', 'item2', 'item3', 'item4', 'item5']
Not sure about what you want but I would do it in python with the following piece of code using a regex to split the string :
import re
s="item1, item2 item3 item4 , item5"
re.split('\s*,*\s*',s)
Gives as output :
['item1', 'item2', 'item3', 'item4', 'item5']