ruby-1.9.3-p0 :055 > a = '"Smith, Joe" < jsmith@example.com >, "Jackson, Joe" < jjackson@example.com >'; ruby-1.9.3-p0 :056 > b = a.scan(/<(.*?)>/).flatten => [" jsmith@example.com ", " jjackson@example.com "] ruby-1.9.3-p0 :057 > c = a.scan(/"(.*?)"/).flatten => ["Smith, Joe", "Jackson, Joe"]
The index of the name / email address in each array is the same, so c [1] is the name for b [1] email.
Based on your comment, how about it:
ruby-1.9.3-p0 :008 > a = '"Smith, Joe" < jsmith@example.com >, "Jackson, Joe" < jjackson@example.com >'; ruby-1.9.3-p0 :009 > b = '" test@domain.com , test2@domain.com "'; ruby-1.9.3-p0 :010 > b.scan(/\w*@\w*\.\w*/) => [" test@domain.com ", " test2@domain.com "] ruby-1.9.3-p0 :011 > a.scan(/\w*@\w*\.\w*/) => [" jsmith@example.com ", " jjackson@example.com "]
This is almost the same as what you added to your question, just more compact.
source share