in reply to Re^2: regex for multiple capture within boundary
in thread regex for multiple capture within boundary
That's exactly it (although there could be 0 elements if the match fails).
my @nums = ($x =~ /\s(\S+)/)[0] =~ /(\d+)/g;
could also be written as
my @nums = ($x =~ /\s(\S+)/ ? $1 : undef) =~ /(\d+)/g;
If you're going to use /g, drop the \s:
# @nums = ('3', '33'); my $word = 2; my @nums = ($x =~ /(\S+)/g)[$word] =~ /(\d+)/g;
or use split:
# @nums = ('3', '33'); my $word = 2; my @nums = (split(' ', $x))[$word] =~ /(\d+)/g;
|
---|
In Section
Seekers of Perl Wisdom