Our application has an invite page where a user can import their address book. We’re using an external service to get at them, so it just puts the results into a textarea. We started out just splitting the results by comma, and quickly figured out that wasn’t going to work because of:
"Smith, Joe" <jsmith@example.com>, "Jackson, Joe" <jjackson@example.com>
It would work between the 2 entries, but also split inside them as well. Just wondering if there’s a well known fool-proof way to make this work.
Maybe regex would work? I’m pretty bad that, could anyone tip me off to what regex would extract just the emails into an array…
Something like this:
emails = recipients.scan(/.*@.*/) <<==== but i know that's not right
EDIT
Looks like something like this might work. Anyone have any suggestions if this would work for special cases:
emails = recipients.scan(/[a-z0-9_.-]+@[a-z0-9-]+\.[a-z.]+/i)
The index of name / email in each array is the same, thus c[1] is the name for the b[1] email.
Based on your comment how about his :
Which is pretty much the same as you added to your question, just more compact.