Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regex to match with exclusions

by kcott (Archbishop)
on Oct 01, 2015 at 15:34 UTC ( [id://1143571]=note: print w/replies, xml ) Need Help??


in reply to Regex to match with exclusions

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143571]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found