Hi all,
Imagine the following string of data containing
d = “Bloggs J. [email protected], Bloggs Keith
[email protected], Bloggs, Mary [email protected],
[email protected]”
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.
Stuart C. wrote in post #986733:
Hi all,
Imagine the following string of data containing
d = “Bloggs J. [email protected], Bloggs Keith
[email protected], Bloggs, Mary [email protected],
[email protected]”
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 certain people feel a need to describe the output
in
words rather than just listing the string you want as the output, which
would leave no room for confusion.
d = “Bloggs J. [email protected], Bloggs Keith
[email protected], Bloggs, Mary [email protected],
[email protected]”
arr = d.scan(/
< #that character…
( #capturing group
[^>]+ #…followed by 1 or more chars that are not a
‘>’
) #end of capture group
> #…followed by that character
/xms)
result = arr.join(‘|’)
puts result
–output:–
[email protected]|[email protected]|[email protected]
Is that what you want?
Whoops. Part of the code got chopped off…it should read:
/xms).flatten
7stud – wrote in post #986830:
Whoops. Part of the code got chopped off…it should read:
/xms).flatten
Thanks for the tip ![:wink: :wink:](/images/emoji/apple/wink.png?v=6)
That code works really well thanks, I did not really think to try
expressions.
Thanks again