[tpm] looking for a regex that returns true on no match
Adam Prime
adam.prime at utoronto.ca
Thu Mar 12 07:30:24 PDT 2009
Fulko Hew wrote:
> Alex asked:
>
> > Couldn't you just use the ~! on the regex instead of ~=?
>
> Nope, see below.
>
> On Thu, Mar 12, 2009 at 9:53 AM, Dave Doyle <dave.s.doyle at gmail.com
> <mailto:dave.s.doyle at gmail.com>> wrote
>
> > Is this because the regexes are being fed in from an external source?
>
> Well the data is a given set, and the regex pattern is what I'm trying
> to develop
>
> > Do you have control of that source?
>
> Nope
>
> Basically there is a simple regex engine somewhere else that says
>
> if (/$regex/) {print "match"; } else { print "no match"; }
>
> and I need a regex pattern that is the 'NOT the given string' pattern.
>
> So for the given the data set: 'bad', 'soso', 'maybe', and 'good'
> I need to be able to say... 'return true if its anything but "good"'.
>
it's !~, not ~!
ie:
aprime at primepc:~$ cat haha.pl
my $text = 'haha';
if ($text !~ /hat/) {
print qq[yay\n];
}
else {
print qq[yay\n];
}
aprime at primepc:~$ perl haha.pl
yay
also, given your example there, why wouldn't you just
return true unless $_ eq 'good';
?
More information about the toronto-pm
mailing list