Negating a regular expression

K

kwest

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

/(hotmail|yahoo|aol)/i"

Is there a way to make this negative?
 
S

Steve Wells

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

as opposed to

$string =~ /(hotmail|yahoo|aol)/i
 
W

wisefamily

kwest said:
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
 
K

kwest

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">
 
E

Eric Schwartz

kwest said:
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
 
T

Tad McClellan

kwest said:
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
 
K

kwest

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

A. Sinan Unur

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
 
K

kwestin

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

Gary E. Ansok

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

Brian McCauley

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.
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top