Reputation: 207
Is there a way to decipher which scenario is being reported by match $&
when regexp searches for a pattern /[XY]{15,20}[WZ]{10,15}[XY]{15,20}/g
in a string that has mutliple matches for the regexp?
I'm trying to avoid combinatorics of:
[XY]{15}[WZ]{10}[XY]{15}
[XY]{15}[WZ]{10}[XY]{16}
[XY]{15}[WZ]{10}[XY]{17}
...
[XY]{16}[WZ]{10}[XY]{15}
[XY]{17}[WZ]{10}[XY]{15}
...
from which I would know which scenario is being reported.
By scenario I mean is it: [XY]{15}[WZ]{10}[XY]{16}
that has match in the string or is it [XY]{16}[WZ]{10}[XY]{15}
?
Any advice is appreciated.
Upvotes: 0
Views: 122
Reputation: 35208
As mpapec already suggested, you just need to capture those subexpressions if you want to determine more info about them.
while ($string =~ /(([XY]{15,20})([WZ]{10,15})([XY]{15,20}))/g {
my ($whole, $xy1, $wz, $xy2) = ($1, $2, $3, $4);
print join(',', map length, ($xy1, $wz, $xy2)), "\n";
Upvotes: 2