in reply to Parsing email addresses (was: Regex Help)

See this node for some answers to your problem.

A quick solution, however, would be to /\@(.+?)\s/; or ($user, $domain) = split(/\@/, $email, 2);

Update: Fixed a yet another typo, got rid of a temp array... thanks grep :)

John J Reiser
newrisedesigns.com

Replies are listed 'Best First'.
Re: Re: (nrd)Regex Help
by sauoq (Abbot) on Aug 29, 2002 at 06:32 UTC
    /\@(.+?)\s/;

    That wouldn't match his example, "fake@email.com" due to the \s and the fact that his example has no whitespace. You also don't need to escape the @.

    This:

    /@(.*)/
    would work.

    Note that, without anchoring the end of it, you must .* rather than .*? because the latter can (and would) match nothing (i.e. an empty match) and end.

    Of course, I agree that you shouldn't use a regex for this anyway so caveats, disclaimers, etc. :-)

    -sauoq
    "My two cents aren't worth a dime.";
    

      Very true.

      I assumed he'd be pulling the addresses out of a text file (or HTML) and now that I think about it, (") would be a better ending boundary for HTML.

      D'oh. You know what they say when you assume... : /

      John J Reiser
      newrisedesigns.com