# Get all emails in a string?

**URL:** https://rubytalk.org/t/get-all-emails-in-a-string/55789
**Category:** ruby-talk
**Created:** [13 October 2009 17:52 UTC](https://rubytalk.org/t/get-all-emails-in-a-string/55789 "2009-10-13T17:52:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Joshua\_Muheim](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Joshua\_Muheim](https://rubytalk.org/u/Joshua_Muheim)
#### Post date: [13 October 2009 17:52 UTC](https://rubytalk.org/t/get-all-emails-in-a-string/55789/1 "2009-10-13T17:52:09Z")

</div>

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Alexey\_Bovanenko](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Alexey\_Bovanenko](https://rubytalk.org/u/Alexey_Bovanenko)
#### Post date: [13 October 2009 19:37 UTC](https://rubytalk.org/t/get-all-emails-in-a-string/55789/2 "2009-10-13T19:37:26Z")

</div>

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  
&nbsp;&nbsp;&nbsp;puts "#{$1}";  
end  
end

> **···**
>
> On Tue, Oct 13, 2009 at 9:52 PM, Joshua Muheim \<forum@josh.ch\> 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  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)
#### Post date: [14 October 2009 04:17 UTC](https://rubytalk.org/t/get-all-emails-in-a-string/55789/3 "2009-10-14T04:17:41Z")

</div>

Joshua Muheim 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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)
#### Post date: [14 October 2009 04:18 UTC](https://rubytalk.org/t/get-all-emails-in-a-string/55789/4 "2009-10-14T04:18:38Z")

</div>

7stud -- wrote:

> Joshua Muheim 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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
