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.
Newb N. (Guest)
on 2009-01-27 13:07
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
Tiago N. (Guest)
on 2009-01-27 13:23
(Received via mailing list)
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 :
http://www.regular-expressions.info/ruby.html
http://www.rubyist.net/~slagell/ruby/regexp.html

Regards,
-tiago
Jesús Gabriel y Galán (Guest)
on 2009-01-27 14:31
(Received via mailing list)
On Tue, Jan 27, 2009 at 12:05 PM, Newb N. <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

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", "Vs", "kannan",
"angleritech.com"]

Hope this helps,

Jesus.
Robert K. (Guest)
on 2009-01-27 15:51
(Received via mailing list)
2009/1/27 Newb N. <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
This topic is locked and can not be replied to.