Get all emails in a string?

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

Hi!

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

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

In code:

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

Joshua M. wrote:

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.

7stud – wrote:

Joshua M. wrote:

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs