Email parsing - help please

Discussion in 'Ruby' started by Stuart Clarke, Mar 10, 2011.

  1. Hi all,

    Imagine the following string of data containing

    d = "Bloggs Joe <>, Bloggs Keith
    <>, Bloggs, Mary <>,
    "

    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/.
    Stuart Clarke, Mar 10, 2011
    #1
    1. Advertising

  2. Stuart Clarke

    7stud -- Guest

    Stuart Clarke wrote in post #986733:
    > Hi all,
    >
    > Imagine the following string of data containing
    >
    > d = "Bloggs Joe <>, Bloggs Keith
    > <>, Bloggs, Mary <>,
    > "
    >
    > 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 <>, Bloggs Keith
    <>, Bloggs, Mary <>,
    "

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

    --output:--
    ||

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Mar 11, 2011
    #2
    1. Advertising

  3. Stuart Clarke

    7stud -- Guest

    7stud --, Mar 11, 2011
    #3
  4. 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/.
    Stuart Clarke, Mar 11, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    492
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    525
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,722
    Mike Hewson
    Jan 7, 2005
  4. dont bother

    Help on Email Parsing

    dont bother, Feb 23, 2004, in forum: Python
    Replies:
    3
    Views:
    344
    John Roth
    Feb 23, 2004
  5. =?Utf-8?B?V2FyZHk=?=

    RE: Please help *PLEASE PUT ME ON YOUR EMAIL LIST*

    =?Utf-8?B?V2FyZHk=?=, Aug 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    432
    =?Utf-8?B?V2FyZHk=?=
    Aug 19, 2006
Loading...

Share This Page