Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Email parsing - help please

Reply
Thread Tools

Email parsing - help please

 
 
Stuart Clarke
Guest
Posts: n/a
 
      03-10-2011
Hi all,

Imagine the following string of data containing

d = "Bloggs Joe <(E-Mail Removed)>, Bloggs Keith
<(E-Mail Removed)>, Bloggs, Mary <(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed)"

As you can see the format of the email addresses is not consistant, for
that reason, I want to parse this string of data and seperated each
address with a pipe (|).

I have found a solution in java like so:

javax.mail.internet.InternetAddress.parse(d).map { |add| add.toString()
}.join('|')

This works pretty well, however I cannot find a Ruby alternative. I have
tried TMail, using the following:

TMail::Address.parse(d).map{ |add| add.toString() }.join('|')

This however fails as I cannot call map because the data is not in an
array.

Does anyone have any suggestions? I would really appreciate any
guidance.

Thanks a lot.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      03-11-2011
Stuart Clarke wrote in post #986733:
> Hi all,
>
> Imagine the following string of data containing
>
> d = "Bloggs Joe <(E-Mail Removed)>, Bloggs Keith
> <(E-Mail Removed)>, Bloggs, Mary <(E-Mail Removed)>,
> (E-Mail Removed)"
>
> As you can see the format of the email addresses is not consistant, for
> that reason, I want to parse this string of data and seperated each
> address with a pipe (|).


It's always puzzling why people like you don't just list the output they
want. For some reason you people feel a need to describe the output in
words rather than just listing the string you want to end up with.


d = "Bloggs Joe <(E-Mail Removed)>, Bloggs Keith
<(E-Mail Removed)>, Bloggs, Mary <(E-Mail Removed)>,
(E-Mail Removed)"

arr = d.scan(/<([^>]+)>/).flatten
result = arr.join('|')
puts result

--output:--
(E-Mail Removed)|(E-Mail Removed)

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      03-11-2011
Whoops. Part of the code got chopped off...it should read


/xms).flatten

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Stuart Clarke
Guest
Posts: n/a
 
      03-11-2011
7stud -- wrote in post #986830:
> Whoops. Part of the code got chopped off...it should read:
>
>
> /xms).flatten


Thanks for the tip

That code works really well thanks, I did not really think to try
expressions.

Thanks again

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Please help *PLEASE PUT ME ON YOUR EMAIL LIST* =?Utf-8?B?V2FyZHk=?= ASP .Net 0 08-19-2006 01:19 PM
Re: Please Help *PLEASE PUT ME ON YOUR EMAIL LIST* me Computer Support 1 08-15-2006 03:31 AM
Please help *PLEASE PUT ME ON YOUR EMAIL LIST* ray...i need to pay my bill and it works Computer Support 0 08-14-2006 03:18 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments