Changing your regex to

/my background error (\d+):(?!.+my3\.exe)/

seems to capture what you're after.

Here's a few tests:

$ perl -Mstrict -Mwarnings -E 'while (<>) { if (/my background error ( +\d+):(?!.+my3\.exe)/ ) { say $1 } }' blah blah my background error 1234: blah blah 1234 blah blah my background error 1234: blah blah my3.exe blah blah blah my background error 1234: blah blah my4.exe blah 1234 blah blah my background error 1234: my3.exe blah blah my background error 1234:my3.exe 1234 ^C

Note the last one with 1234:my3.exe is a match: which seems to follow the pattern you're describing. If you don't want that line either, use .* instead of .+, i.e. change (?!.+my3\.exe) to (?!.*my3\.exe).

UPDATE

I noticed you wanted to capture the text after the error number as well as that number. The solution above doesn't do that. The following regex will:

/my background error (\d+): ((?!.*my3\.exe).+)/

Retested:

$ perl -Mstrict -Mwarnings -E 'while (<>) { if (/my background error ( +\d+): ((?!.*my3\.exe).+)/ ) { say qq{$1 = \"$2\"} } else { say q{NO M +ATCH} } }' blah blah my background error 1234: blah blah 1234 = "blah blah" blah blah my background error 1234: blah blah my3.exe blah NO MATCH blah blah my background error 1234: blah blah my4.exe blah 1234 = "blah blah my4.exe blah" blah blah my background error 1234: my3.exe NO MATCH blah blah my background error 1234:my3.exe NO MATCH blah blah my background error 1234: my4.exe 1234 = "my4.exe" ^C

-- Ken


In reply to Re: negated word issue by kcott
in thread negated word issue by Anonymous Monk

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.