I have a file containing records separated by a |.
In order to classify these entries, I first split each line, and match certain fields against a hash of filters.

The filters are loaded from a configuration file at run-time.
I am thus limited to $var[5] =~ /$regex/ (or at least I think so) for my matching.
Is it possible to get something like this to work:

$re[0] = qr (.*(?!system))i; $re[1] = qr (system)i; $v[0] = "oneitem"; $v[1] = "anothersystem"; for $a (@v) { for $r (@re) { print "\nRegex: $r\tValue: $a\n"; if ($a =~ /$r/) { print "$a matches $r\n" ; } } }

As this results in:

Regex: (?-xism:.*(?!system)) Value: oneitem oneitem matches (?-xism:.*(?!system)) Regex: (?-xism:system) Value: oneitem Regex: (?-xism:.*(?!system)) Value: anothersystem anothersystem matches (?-xism:.*(?!system)) Regex: (?-xism:system) Value: anothersystem anothersystem matches (?-xism:system)

Which is not what I want...
Is it possible to construct a regex that "matches if doesn't contain" ?


In reply to Backtracking problem with .*(?!bar) by olivierp

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.