Hey, I can\'t figure out how to write a regular expression for my website, I would like to let the user input a list of items (tags) separated by comma or by comma and a spa
something like this should work: ((apple|pie|applepie),\s?)*
I often work with coma separated pattern, and for me, this works :
((^|[,])pattern)+
where "pattern" is the single element regexp
Here's a simpler solution:
console.log("test, , test".match(/[^,(?! )]+/g));
It doesn't break on empty properties and strips spaces before and after properties.
([^,]*)
Look For Commas within a given string, followed by separating these. in regards to the whitespace? cant you just use commas? remove whitespace?
This might work:
([^,]*)(, ?([^,]*))*
Assuming the words in your list may be letters from a to z and you allow, but do not require, a space after the comma separators, your reg exp would be [a-z]+(,\s*[a-z]+)*
This is match "ab" or "ab, de", but not "ab ,dc"