0

I'm trying to use regex to grab the email address in a forwarded message. Something like this:

test_string = '"---------- Forwarded message ----------\\r\\nFrom: <test@email.com>\\r\\nDate: Sun, Feb 2, 201\"'

I'd like to be able to extract "test@email.com" or "From: ". So far I've tried:

test_string.scan(/From:<(.*)>/) 

And it doesn't find the email address. Am I missing something?

Thanks!

Delos Chang
  • 1,823
  • 3
  • 27
  • 47
  • 1
    Don't do that. Just don't. A regex that simple isn't nearly sophisticated to accurately catch real email addresses. See http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address?rq=1, which is about validation, but will give you a good idea what you really need, and how difficult it is to do correctly. – the Tin Man Feb 06 '14 at 19:29
  • Not trying to validate, just trying to extract emails. I'm okay if some emails fall through the typical regex. – Delos Chang Feb 06 '14 at 19:44

1 Answers1

0

You are missing the space between From: and <(.*)>

Jack
  • 2,750
  • 2
  • 27
  • 36