RegExp for matching word "[email protected]" or word "[email protected]" ?

Discussion in 'Perl Misc' started by Gerd Pohlmann, Feb 4, 2004.

  1. Just a stupid question from a newbie:
    How do I setup a reg exp which matches if the text (line) contains
    either the full word "" or the full word "" (without quotes)?

    (|)

    does not work.

    Gerd
     
    Gerd Pohlmann, Feb 4, 2004
    #1
    1. Advertisements

  2. Does not work?

    Please post a small but complete program, where you have included "use
    strict;" and "use warnings;" at the top, and that illustrates your
    problem. Let us know which error or warning messages you get (if any),
    and try to avoid just saying "does not work".
     
    Gunnar Hjalmarsson, Feb 4, 2004
    #2
    1. Advertisements


  3. Of course not, it is not Perl code.

    Did you mean to ask a question about Perl code?

    If so, then show us the Perl code that your question is about...
     
    Tad McClellan, Feb 4, 2004
    #3
  4. Gerd Pohlmann

    Robert Meyer Guest

    Am Wed, 04 Feb 2004 13:47:49 +0100 schrieb Gerd Pohlmann:
    Hi Gerd,

    you have to mask the @ and the . with a \

    So it looks like this
    (karl\@aol\.com|paul\@hotmail\.com)

    If you want to use it in a Perl Program then you must includ it into two /
    like this
    (/karl\@aol\.com/|/paul\@hotmail\.com/)

    If you want to learn more about Regexp then use ISBN 3-89721-349-4 from
    O'Reilly.

    greets
    Robert
     
    Robert Meyer, Feb 4, 2004
    #4
  5. Gerd Pohlmann

    J Krugman Guest

    That looks like a bitwise OR of two scalars... I suppose it would
    work, but it's not terribly good Perl. How about

    /karl\@aol\.com|paul\@hotmail\.com/

    ?
     
    J Krugman, Feb 4, 2004
    #5
  6. Yeah, but since the email addresses are plain strings, it would
    probably be even better Perl to make use of the index() function
    instead of a regular expression.
     
    Gunnar Hjalmarsson, Feb 4, 2004
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.