Get all emails in a string?

J

Joshua Muheim

Hi all

I know this question is quite old, but I need to detect all the email
addresses in a string. I guess I could use a RegEx, and I stumbled upon
TMail that seems to do a great job validating emails. But I just can't
find the RegEx that TMail uses...? Anybody does?

Thanks for help
Josh
 
A

Alexey Bovanenko

Hi!

I suggest you very simple regex which can help find all emails:

[a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]+\.\w{2,4}

In code:

File.open("file_with_emails.txt").each do |line|
line.scan(/([a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]+\.\w{2,4})/) do
puts "#{$1}";
end
end
 
7

7stud --

Joshua said:
Hi all

I know this question is quite old, but I need to detect all the email
addresses in a string. I guess I could use a RegEx, and I stumbled upon
TMail that seems to do a great job validating emails. But I just can't
find the RegEx that TMail uses...? Anybody does?

Thanks for help
Josh

Why don't you point out the deficiencies with the answers given in your
previous thread where you asked the exact same question? The proper
place to do that would be, wait for it...your previous thread.
 
7

7stud --

7stud said:
Why don't you point out the deficiencies with the answers given in your
previous thread where you asked the exact same question? The proper
place to do that would be, wait for it...your previous thread.

Also, despite what you may think, this forum isn't a free programming
service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top