Forum: Ruby Name Extraction

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-01-27 12:07
Hi Friends

i have following string

jayabharathy@angleritech.com~Vs~kannan@angleritech.com

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
A745f7d401d0a9bf80a5d5d94c961a05?d=identicon&s=25 Tiago Nogueira (Guest)
on 2009-01-27 12:23
(Received via mailing list)
Newb Newb 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 :
http://www.regular-expressions.info/ruby.html
http://www.rubyist.net/~slagell/ruby/regexp.html

Regards,
-tiago
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2009-01-27 13:31
(Received via mailing list)
On Tue, Jan 27, 2009 at 12:05 PM, Newb Newb <revathy.p@angleritech.com>
wrote:

> i have following string
>
> jayabharathy@angleritech.com~Vs~kannan@angleritech.com
>
> 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

For example:

irb(main):001:0> a =
"jayabharathy@angleritech.com~Vs~kannan@angleritech.com"
=> "jayabharathy@angleritech.com~Vs~kannan@angleritech.com"
irb(main):006:0> a.split(/[@~]/)
=> ["jayabharathy", "angleritech.com", "Vs", "kannan",
"angleritech.com"]

Hope this helps,

Jesus.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-01-27 14:51
(Received via mailing list)
2009/1/27 Newb Newb <revathy.p@angleritech.com>:
> 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
This topic is locked and can not be replied to.