in reply to Regex for e-mail contacts name

lothar4ever,

Why not show us something you tried?

You'll get a lot more help, if we have something to help analyze with you.

Just make sure to use <code> ... </code>.

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Regex for e-mail contacts name
by lothar4ever (Initiate) on Jan 23, 2012 at 20:01 UTC
    Things i've tried:
    s/(?<=")[^"><]*(?=")//g
    s/\".+?\<//g
    There is a few more, but i don't remember them, there was so many tries, this where the last 2.

      lothar4ever,

      You don't say where the data is coming from, so to get your $string to be what you want, you need to escape the '@' signs:

      my $string = qq|sean\@gmail.com, "richard" <richard\@gmail.com>, "john +" <john\@gmail.com>, <jack\@gmail.com>|;

      For this, I would use 'split': ( tested code, but re-typed from X-Terminal ):

      my @email = split(/\,/,$string); for my $var( 0 .. $#email ) { print "$email[$var]\n"; ..... # put additional code here }

      Now you have an array that you could use a regex or 'split' again on each element of the array in get the format you want. If the data is coming from disk, it maybe that each email address is on a line terminated with a 'CR'.

      Hope this helps.

      "Well done is better than well said." - Benjamin Franklin

        thanks for the reply but that is not what i need.
        The string is coming from an incoming email, i don't know what it is. This is why i need a regex, because all email clients send emails with different formats (Outlook uses names, Gmail is plain, Hotmail sends with <>).