There's more than one way to do things | |
PerlMonks |
Re: Complex regex questionby Athanasius (Archbishop) |
on Sep 25, 2019 at 06:39 UTC ( [id://11106666]=note: print w/replies, xml ) | Need Help?? |
Hello Cody Fendant, Your regex is actually working correctly: in the alternation m{ (\d+) (a|b) | (a|b) (\d+) }gx, the 4 captures are assigned to $1, $2, $3, and $4, even though only 2 of the 4 matches are possible in any particular instance (hence, you will always get 2 undef results). To avoid this behaviour, you can use the Extended Pattern (?|pattern) (from Perl 5.10.0 on):
Output:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|