Using Perl and Regex, is it possible to create a one-liner regex to match some phrases while NOT matching other? The rules are stored in a hash and the qualifier (column) needs to match the expression fed to it.
I have an object that contains qualifiers that I would prefer to feed in as a one-line regex. For example:
my %filters = {
  rule_a  => {
    regex  => {
      qualifier_a => qr/fruits/i,
      qualifier_b => qr/apples|oranges|!bananas/i, # NOT bananas
    }
  }
}
So, in this case, I want to match qualifier_a containing 'fruits' and qualifier_b containing 'apples', 'oranges', but NOT 'bananas'.
The script loops over each qualifier as follows:
my $match = 1; # Assume a match    
foreach my $qualifier (keys %filters{rule_a}{regex}) {
  # If fails to match, set match as false and break out of loop
  $match = ($qualifier =~ /%filters{rule_a}{regex}{$qualifier}/) ? 1 : 0);
  if(!$match){
   last;
  }
}
if($match){
  # Do all the things
}
Thoughts?
 
     
     
    