# Name Extraction

**URL:** <https://www.ruby-forum.com/t/name-extraction/158733>\
**Category:** Ruby\
**Created:** [January 27, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/name-extraction/158733 "2009-01-27T12:07:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 27, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/name-extraction/158733/1 "2009-01-27T12:07:15Z")

</div>

Hi Friends

i have following string

removed\_email\_address@domain.invalid~Vs~removed\_email\_address@domain.invalid

the above string has 2 email ids in it.but i need only names of it.

i want to extract only the names

jayabharathy

kannan

how can i implemend that  
Kindly Let me Know

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 27, 2009, 12:23pm UTC](https://www.ruby-forum.com/t/name-extraction/158733/2 "2009-01-27T12:23:01Z")

</div>

Newb N. escreveu:

> jayabharathy
> 
> kannan
> 
> how can i implemend that  
> Kindly Let me Know

Hi !  
I think you can do this with regular expressions.  
look some at :

> **[Ruby Regexp Class - Regular Expressions in Ruby](https://www.regular-expressions.info/ruby.html)**
>
> Learn how to use regular expressions with Ruby and the Ruby Regexp class

[http://www.rubyist.net/~slagell/ruby/regexp.html](http://www.rubyist.net/~slagell/ruby/regexp.html)

Regards,  
-tiago

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 27, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/name-extraction/158733/3 "2009-01-27T13:31:05Z")

</div>

On Tue, Jan 27, 2009 at 12:05 PM, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> i have following string
> 
> removed\_email\_address@domain.invalid~Vs~removed\_email\_address@domain.invalid
> 
> the above string has 2 email ids in it.but i need only names of it.
> 
> i want to extract only the names

Take a look at the split method in String:

[http://www.ruby-doc.org/core/classes/String.html#M000818](http://www.ruby-doc.org/core/classes/String.html#M000818)

For example:

irb(main):001:0\> a =  
“removed\_email\_address@domain.invalid~Vs~removed\_email\_address@domain.invalid”  
=\> “removed\_email\_address@domain.invalid~Vs~removed\_email\_address@domain.invalid”  
irb(main):006:0\> a.split(/[@~]/)  
=\> [“jayabharathy”, “[angleritech.com](http://angleritech.com)”, “Vs”, “kannan”,  
“[angleritech.com](http://angleritech.com)”]

Hope this helps,

Jesus.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 27, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/name-extraction/158733/4 "2009-01-27T14:51:30Z")

</div>

2009/1/27 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> jayabharathy
> 
> kannan

Something like this can work, depends of course on the names that you  
want to allow:

names = str.scan(/(\w+)@[a-z.\_-]+/i).flatten

Cheers

robert
