Email parsing - help please

S

Stuart Clarke

Hi all,

Imagine the following string of data containing

d = "Bloggs Joe <[email protected]>, Bloggs Keith
(e-mail address 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.
 
7

7stud --

Stuart Clarke wrote in post #986733:
Hi all,

Imagine the following string of data containing

d = "Bloggs Joe <[email protected]>, Bloggs Keith
(e-mail address 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 <[email protected]>, Bloggs Keith
(e-mail address removed)"

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

--output:--
(e-mail address removed)|[email protected]|[email protected]
 
S

Stuart Clarke

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top