Re: how to run regex calculation

demerphq <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <CANgJU+WuE0wureESNTGRqyD45U3UoXsfqdavmWZW6o4tCUpP0A@mail.gmail.com>
This isnt really the forum for random perl help, i suggest Perlmonks instead.

$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.

Yves

On Thu, 9 Jan 2020 at 03:36, Wesley Peng <[email protected]> wrote:
>
> Hello
>
> Give the case I have a string,
>
> $str = "2 3 6";
>
> I want to match with:
>
> true if $str =~ /(\d+)\s(\d+)\s($1*$2)/;
>
> that's to say, the thrid column would be (firstCol * SecondCol).
>
> How to write regex for this?
>
> Thank you.



-- 
perl -Mre=debug -e "/just|another|perl|hacker/"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.