regex - Ruby - split string made up of emails at space or comma



I'm working with an instance method inside a class that needs to take in a string of emails and separate them at either a comma OR a space.

I keep getting one or the other to pass, but can't make it so that both the comma and space pass together. I'm trying with regex.

Thanks for your help!

def parse

example of emails list string:,

2 Answers: 

What you need is a character set, denoted by [].


The [] say to match any character in that set. The + is there because you want to treat multiple spaces between emails as a single separator.

@emails.split(/\s|,/) will work // is for multiple and | is to say or