in reply to regexp with mismatches
I think this sort of approach would scale reasonably well for more complicated cases: just include more captures in the initial regex match for the regions that need to pass a second condition, and add more tests using tr/// on each capture -- it might look like this (if this is the direction you're heading towards):if ( /ABC(...).E/ and 2 <= ( $1 =~ tr/D// )) { # get here when the captured region contains 2 or 3 D's }
(Note that tr/// does not affect the contents of capture variables $1, $2, etc.)if ( /D (.{3}) [A-Z]{3,15} (\d{6,8}) [^D]{2}/x and 2 <= ( $1 =~ tr/F//) # first capture contains at least two F +'s and 3 <= ( $2 =~ tr/1//) # second capture contains at least three + 1's ) { # get here when all conditions are met }
i think this also helps keep the logic more coherent and maintainable as code. Loading too many diverse conditions into a single, exhaustive regex can get cumbersome.
|
|---|