Negating a regular expression

Discussion in 'Perl Misc' started by kwest, Nov 17, 2005.

  1. kwest

    kwest Guest

    I am trying to find a way to negate this regular expression:

    /(hotmail|yahoo|aol)/i"

    Is there a way to make this negative?
     
    kwest, Nov 17, 2005
    #1
    1. Advertising

  2. kwest

    Steve Wells Guest

    $string !~ /(hotmail|yahoo|aol)/i

    as opposed to

    $string =~ /(hotmail|yahoo|aol)/i
     
    Steve Wells, Nov 17, 2005
    #2
    1. Advertising

  3. kwest

    Guest

    kwest wrote:
    > I am trying to find a way to negate this regular expression:
    >
    > /(hotmail|yahoo|aol)/i"
    >
    > Is there a way to make this negative?


    Yes. You can write:

    if($string !~ /(hotmail|yahoo|aol)/) {
    # Doesn't match.
    }

    or

    unless($string =~ /(hotmail|yahoo|aol)/) {
    # Doesn't match.
    }

    Hope this helps,
    David
     
    , Nov 17, 2005
    #3
  4. kwest <> wrote:

    > I am trying to find a way to negate this regular expression:
    >
    > /(hotmail|yahoo|aol)/i"



    ! /(hotmail|yahoo|aol)/i;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 17, 2005
    #4
  5. kwest

    kwest Guest

    Problem is I cannot do this within PERL. I am using a PHP tag where you
    can pass a regular expression through. There is a negation attribute,
    that is supposed to negate whatever the outcome is, but it is not
    working.

    <vlvalidator name="EmailRegExp" type="regexp" control="Email"
    errmsg="No Free Email Accounts" RegExp="/(hotmail|yahoo|aol)/i">
     
    kwest, Nov 17, 2005
    #5
  6. "kwest" <> wrote in news:1132270342.208523.188480
    @g43g2000cwa.googlegroups.com:

    > Problem is I cannot do this within PERL.


    s/PERL/Perl/

    > I am using a PHP tag


    Why are you asking here then?

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Nov 17, 2005
    #6
  7. "kwest" <> writes:
    > Problem is I cannot do this within PERL. I am using a PHP tag where you
    > can pass a regular expression through. There is a negation attribute,
    > that is supposed to negate whatever the outcome is, but it is not
    > working.


    Then you should ask in a PHP group. Here, we talk about Perl, so you
    should not be surprised when people give you Perl-specific answers.

    -=Eric
     
    Eric Schwartz, Nov 17, 2005
    #7
  8. kwest <> wrote:

    > Problem is I cannot do this within PERL. I am using a PHP tag



    Then you are in the wrong newsgroup.

    This is the Perl (not PERL) newsgroup.

    We don't discuss PHP here, we discuss Perl here.


    The PHP newsgroup is over that way ==> comp.lang.php


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 18, 2005
    #8
  9. kwest

    kwest Guest

    Because it follows the Perl Regex syntax, just thought some folks would
    know how to negate an expression itself, guess not.
     
    kwest, Nov 18, 2005
    #9
  10. "kwest" <> wrote in news:1132331783.007256.305780
    @g49g2000cwa.googlegroups.com:

    > Because it follows the Perl Regex syntax, just thought some folks would
    > know how to negate an expression itself, guess not.


    It is not even worth explaining to you that you should quote context etc.
    It is also not worth explaining to you that you can find out very easily,
    without violating netiquette and getting plonked, how to negate the
    meaning of the regex in the <vlvalidator> tage itself. Indeed a
    straightforward Google search yields the answer as the first match.

    That said, I have already done it.

    Now, *PLONK*.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Nov 18, 2005
    #10
  11. kwest

    Guest

    Right and the problem is that the negation attribute you mention does
    not work in this case.

    Hence my question how to do this in PERL RegEx. Since the regex is
    specific to the PERL variation figured that this group would have more
    knowledge regarding the specific syntax.

    So my question is really pretty simple is there a way to negate a PERL
    RegEx within the expression language itself, not using any other PERL
    syntax.

    If you don't know the answer then simply don't respond.
     
    , Nov 18, 2005
    #11
  12. In article <>,
    <> wrote:
    >So my question is really pretty simple is there a way to negate a PERL
    >RegEx within the expression language itself, not using any other PERL
    >syntax.


    Does whatever you are using support the *COMPLETE* Perl regular expression
    syntax? As of what Perl version?
     
    Gary E. Ansok, Nov 18, 2005
    #12
  13. wrote:

    > So my question is really pretty simple is there a way to negate a PERL
    > RegEx within the expression language itself, not using any other PERL
    > syntax.


    Yes there is.

    > If you don't know the answer then simply don't respond.


    I know the answer and have idead often been the one to post it in
    previous instanciations of this thread. So I guess that qualifies me to
    respond.

    You have a problem that you've walked into the middle of something and
    don't realise. I suggest you take look at the numerous previous thread
    substancally identical to this one. Perhaps then you'll start to
    understand why the regulars immediately felt sick and tired of you.

    Plugging the words "negate" and "regex" and "comp.lang.perl.misc" into a
    Usenet search engine is left as a exercise for the reader.
     
    Brian McCauley, Nov 18, 2005
    #13
    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. VSK
    Replies:
    2
    Views:
    2,382
  2. Raj Ashar
    Replies:
    2
    Views:
    6,558
    Carl Howells
    Jul 13, 2004
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    883
    Alan Moore
    Dec 2, 2005
  4. Eduardo Bezerra

    Negating a List Of Numbers

    Eduardo Bezerra, Apr 13, 2005, in forum: C++
    Replies:
    19
    Views:
    532
    Jean-Sebastien Samson
    Apr 20, 2005
  5. Alex Fraser
    Replies:
    8
    Views:
    432
    Joe Wright
    Mar 8, 2006
Loading...

Share This Page