[tpm] looking for a regex that returns true on no match

Mike Stok mike at stok.ca
Thu Mar 12 08:17:18 PDT 2009


I've deleted the rest of the thread, but what about

$string =~ /^(?:(?!good).)*$/

to check that $string doesn't contain good?

   DB<1> x 'bad' =~ /^(?:(?!good).)*$/
0  1
   DB<2> x 'good enough' =~ /^(?:(?!good).)*$/
   empty array

Mike

On Mar 12, 2009, at 10:44 AM, Fulko Hew wrote:

>
> On Thu, Mar 12, 2009 at 10:30 AM, Adam Prime  
> <adam.prime at utoronto.ca> wrote:
>
> Fulko Hew wrote:
> Alex asked:
>
>  > Couldn't you just use the ~! on the regex instead of ~=?
>
> ... snip ...
>
>
> 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';
>
>
> Because I'm not allowed to rewrite the code, but simply insert a
> different regex pattern in between the slashes.
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm

-- 

Mike Stok <mike at stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090312/256b5802/attachment.html>


More information about the toronto-pm mailing list