Kevin Kevin - 5 months ago 11
Ruby Question

Regex to match comma followed by whitespace?

I am trying to make a ruby regex to match tags in the format

Toys, Cars, Some Other Topic
but I can't figure out how to make it so that it splits it at after a comma and white space after but not if there is whitespace in a tag

This is what I have come up with but is wrong for now.



You can just use /,\s*/ (which is much simpler than what you've got!):

'Toys, Cars, Some Other Topic'.split /,\s*/
=> ["Toys", "Cars", "Some Other Topic"]