/^(?!.*(?:evil|bad|wrong))/ seems to work for me. The key was the ^ at the begining. With that, it's forced to try from the begining. Otherwise, it keeps searching until it finds a place that doesn't have any of the blacklisted words (for instace, at the end of the string) and then succeeds.
#!/usr/bin/perl -l use strict; use warnings; my @blacklist = ('evil', 'bad', 'wrong'); #$a and $b are bad variable names due to sorting things my $aa = "this string contains no blacklisted tokens"; my $bb = "this string is evil and wrong"; # The regex should express the blacklist is such a way that # # it will match on any string which DOES NOT contain any of # # the tokens in the blacklist, and it will fail to match on # # any string which DOES contain tokens from the blacklist. # my $regex = qr/^(?!.*(?:evil|bad|wrong))/; if (($aa =~ m/$regex/) && !($bb =~ m/$regex/)) { print "Woohoo"; }

In reply to Re: Blacklisting with a Regular Expression by Eimi Metamorphoumai
in thread Blacklisting with a Regular Expression by BenjiSmith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.