perl - Capturing Group with regex -
perl - Capturing Group with regex -
i using code follows,
code:
$str = 123455; if ($str =~ m/([a-z]+)|(\d+)/ { print "$1\n"; } i know not print result because should give $2. want result using same code changing regular expression.
is possible it?
note :
please not provide result below,
$str = 123455; if ($str =~ m/(?:[a-z]+)|(\d+)/ { print "$1\n"; }
you can utilize (?| .. ) alternative capture grouping numbering,
use 5.010; # regex feature available since perl 5.10 $str = 123455; if ($str =~ m/(?| ([a-z]+)|(\d+) )/x) { print "$1\n"; } regex perl
Comments
Post a Comment