开发者

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

I'm trying to extract information from an email address like so in ruby:

Email: Joe Schmo <joeschmo@abc123.com>

to get these three variables:

name = ?
email = ?
domain = ?

I've tried searching everywhere but can't seem to find how to do it correctly. Here's what I have so far:

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

name = (/^Email\: (.+) &l开发者_如何学运维t;(.+)>@[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 those three variables correctly?


/Email: (.+) <(.+?)@(.+)>/

Then grab what you want out of the capturing groups.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜