Regex: How do you get / retrieve information from email using regular expressions (in ruby)?

I am trying to extract information from an email address, for example in ruby:

Email: Joe Schmo <joeschmo@abc123.com>

to get these three variables:

name = ?
email = ?
domain = ?

I tried searching everywhere, but cannot find how to do it right. Here is what I still have:

the_email_line = "Email: Joe Schmo <joeschmo@abc123.com>"

name = (/^Email\: (.+) <(.+)>@[A-Z0-9.-]+\.(.+)/).match(the_email_line)[1]
email = (/^Email\: (.+) <(.+)>@[A-Z0-9.-]+\.(.+)/).match(the_email_line)[2]
domain = (/^Email\: (.+) <(.+)>@[A-Z0-9.-]+\.(.+)/).match(the_email_line)[3]

Any idea on how to get these three variables correctly?

+3
source share
1 answer
/Email: (.+) <(.+?)@(.+)>/

Then capture what you want from capture groups.

+5
source

Source: https://habr.com/ru/post/1732435/


All Articles