Re: how to run regex calculation

demerphq <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <CANgJU+VPK32E9Cxy_xegBSdsLW-ppBe=iWq_ebBTQTpaVN8Q5A@mail.gmail.com>
Sure you can. See joseph he's answer. 😀

Yves

On Mon, 13 Jan 2020, 05:06 Paul B. Henson, <[email protected]> wrote:

> On Thu, Jan 09, 2020 at 10:36:19AM +0800, Wesley Peng wrote:
>
> > $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?
>
> I don't think you can do it directly in the regex. You'll need to do the
> math separately:
>
>         if ($str =~ /^(\d+)\s(\d+)\s(\d+)$/ && $3 == $1 * $2) {
>                 print "true\n"
>         }
>         else {
>                 print "false\n";
>         }
>
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.