I'm not sure where you're trying to go with your regex for "multiple repetitions with variable length", (that is, it's not clear what sorts of string sets you want to match), but one alternative for the initial case is a two-step test, where the second step uses tr///:
if ( /ABC(...).E/ and 2 <= ( $1 =~ tr/D// )) {
# get here when the captured region contains 2 or 3 D's
}
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 ( /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
}
(Note that tr/// does not affect the contents of capture variables $1, $2, etc.)
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.