in reply to Re^2: Question on Regex grouping
in thread Question on Regex grouping
Numbering of captures counts per match/regex, of which you have two here - the one with the 8-digit capture being evaluated last.
If you wanted to extract the 5-digit number from the first regex, you could simply reverse the order of the &&-combined tests:
if (($arr =~ / (\w*)(def)(\d{8})/) && ($arr =~ /(\w*)(abc)(\d{5})/)) {
Now, $3 is the 5-digit number.
If you wanted to keep all captures, you could assign them to variables, e.g.:
if (( my ($c1, $c2, $c3) = $arr =~ /(\w*)(abc)(\d{5})/) && ( my ($c4, $c5, $c6) = $arr =~ / (\w*)(def)(\d{8})/)) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Question on Regex grouping
by ajguitarmaniac (Sexton) on Dec 21, 2010 at 07:05 UTC | |
by Anonyrnous Monk (Hermit) on Dec 21, 2010 at 07:12 UTC | |
by ajguitarmaniac (Sexton) on Dec 21, 2010 at 07:40 UTC | |
by AnomalousMonk (Archbishop) on Dec 22, 2010 at 05:38 UTC |