It probably won't ever work. The problem is the * (star/asterisk) after
\1 is being interpreted in the context of regular expressions, ie,
"zero-or-more matches", and not as a multiplication operator. In fact,
~]$ perl -Mstrict -le 'my $str = "2 3 23"; print "true" if
$str=~/(\d+)\s(\d+)\s(\1*\2)/'
...does indeed print "true"
It would probably make the most sense to not try to do this as a
one-liner (why do we perl programmers love to be cute like that?), and
simply break it up into two steps:
$str =~ s/(\d+)\s(\d+)\s(\d+)/;
print "true" if ($1*$2 == $3);
- Michael
On 1/9/2020 12:39 AM, Wesley Peng wrote:
Hallo
on 2020/1/9 16:35, demerphq wrote:
$str=~/(\d+)\s(\d+)\s(\1*\2)/
$1 refers to the capture buffers from the last completed match, \1
inside of the pattern part of a regex refers to the capture buffer of
the currently matching regex.
This doesn't work too.
perl -Mstrict -le 'my $str = "2 3 6"; print "true" if
$str=~/(\d+)\s(\d+)\s(\1*\2)/'
nothing printed.
Regards.