RegExp for matching word "karl@aol.com" or word "paul@hotmail.com" ?

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. Advertising

  2. Re: RegExp for matching word "" or word ""?

    Gerd Pohlmann wrote:
    > 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.


    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
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 4, 2004
    #2
    1. Advertising

  3. Gerd Pohlmann <> wrote:


    > (|)
    >
    > does not work.



    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 SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 4, 2004
    #3
  4. Gerd Pohlmann

    Robert Meyer Guest

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

    > 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


    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

    --
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't.
    http://www.one-m.de
    http://www.lugbz.org/documents/smart-questions_de.html
     
    Robert Meyer, Feb 4, 2004
    #4
  5. Gerd Pohlmann

    J Krugman Guest

    In <> Robert Meyer <> writes:

    >(/karl\@aol\.com/|/paul\@hotmail\.com/)


    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. Re: RegExp for matching word "" or word ""?

    J Krugman wrote:
    > Robert Meyer writes:
    >>
    >> (/karl\@aol\.com/|/paul\@hotmail\.com/)

    >
    > 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/
    >
    > ?


    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
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 4, 2004
    #6
    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. Andrew Stewart
    Replies:
    6
    Views:
    142
    Andrew Stewart
    Dec 14, 2007
  2. Joao Silva
    Replies:
    16
    Views:
    408
    7stud --
    Aug 21, 2009
  3. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    262
    Marc Bissonnette
    Jan 13, 2004
  4. Replies:
    4
    Views:
    137
  5. Bobby Chamness
    Replies:
    2
    Views:
    267
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page