G'day fazedandconfused,

The regex you show (i.e. ([A-Z.]*BO)<br>) matches nothing!

To match all lines containing a string ending ".BO", you could use a regex like this:

qr{ : ( .*? \. BO \b ) }x

This captures:

DI.CATALOGUE.ITEM.IMPORT.BO DI.PRODUCT.HIERARCHY.IMPORT.BO DI.CATSETUP.PRODUCT.IMPORT.BO ATP.CANCEL.PARCEL.CONFIRM.EXPORT.BO ATP.DELIVERY.DEFINITION.EXPORT.BO ATP.FOREIGN.PARCEL.EXPORT.BO ATP.PARCEL.DESPATCH.EXPORT.BO

For your data, consider capturing your "most situations" strings (as shown above) and then, separately, excluding your "particular requirement" lines. This should provide more flexibility by allowing you to conditionally include a (possibly variable) "particular requirement" regex.

Here's my test:

#!/usr/bin/env perl -l use strict; use warnings; my $most_situations_re = qr{ : ( .*? \. BO \b ) }x; my $particular_requirement_exclude_re = qr{ PRODUCT }x; while (<DATA>) { next unless /$most_situations_re/; my $capture = $1; next if $capture =~ /$particular_requirement_exclude_re/; print $capture; } __DATA__ red Queue TEST1:DI.CATALOGUE.ITEM.IMPORT.BO has depth 10 (critical: 10 +, warn: 1) red Queue TEST1:DI.PRODUCT.HIERARCHY.IMPORT.BO has depth 20 (critical: + 10, warn: 1) yellow Queue TEST1:DI.CATSETUP.PRODUCT.IMPORT.BO has depth 9 (warn: 1, + critical: 10) green Queue TEST1:ATP.CANCEL.PARCEL.CONFIRM.EXPORT.BO has depth 0 (war +n: 1, critical: 10) green Queue TEST1:ATP.CANCEL.PARCEL.CONFIRM.EXPORT.LQ has depth 0 (war +n: 30, critical: -1) green Queue TEST1:ATP.DELIVERY.DEFINITION.EXPORT.BO has depth 0 (warn: + 1, critical: 10) green Queue TEST1:ATP.DELIVERY.DEFINITION.EXPORT.LQ has depth 0 (warn: + 10, critical: -1) green Queue TEST1:ATP.FOREIGN.PARCEL.EXPORT.BO has depth 0 (warn: 1, c +ritical: 10) green Queue TEST1:ATP.FOREIGN.PARCEL.EXPORT.LQ has depth 0 (warn: 5, c +ritical: -1) green Queue TEST1:ATP.PARCEL.DESPATCH.EXPORT.BO has depth 0 (warn: 1, +critical: 10)

Output:

DI.CATALOGUE.ITEM.IMPORT.BO ATP.CANCEL.PARCEL.CONFIRM.EXPORT.BO ATP.DELIVERY.DEFINITION.EXPORT.BO ATP.FOREIGN.PARCEL.EXPORT.BO ATP.PARCEL.DESPATCH.EXPORT.BO
"This is where my knowledge of regular expression lets me down ..."

I don't know your level of regex knowledge. One or more of these should help:

— Ken


In reply to Re: Regex to match with exclusions by kcott
in thread Regex to match with exclusions by fazedandconfused

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.