Re: how to run regex calculation

2020-01-13 Thread demerphq
Sure you can. See joseph he's answer.  Yves On Mon, 13 Jan 2020, 05:06 Paul B. Henson, 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

Re: how to run regex calculation

2020-01-12 Thread Paul B. Henson
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

Re: how to run regex calculation

2020-01-12 Thread Alex Mestiashvili
I am not subscribed to the list, so sending to the authors too. This seem to work: echo "2 3 6" |perl -Mstrict -pE 's{(\d+)\s(\d+)\s(\d+)}{my $r="false";$r="true" if $3 == eval"$1*$2";$r}e;' perl -Mstrict -lE 'my $str = "2 3 7"; $str =~ s{(\d+)\s(\d+)\s(\d+)}{my

Re: how to run regex calculation

2020-01-10 Thread demerphq
On Thu, 9 Jan 2020 at 17:25, MIchael Capone wrote: > > It probably won't ever work. Joseph He's solution works just fine: perl -le'for my $str ("2 3 6", "1 1 1" ,"1 2 3","123 456 56088"){ print "($str)", $str =~ /(\d+)\s(\d+)\s(??{ $1 * $2 })/ ? " matched" : " rejected"}' (2 3 6) matched (1 1

Re: how to run regex calculation

2020-01-09 Thread MIchael Capone
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

Re: how to run regex calculation

2020-01-09 Thread Jan Pazdziora
On Thu, Jan 09, 2020 at 05:21:38PM +0800, Wesley Peng wrote: > what does (??{$1*$2}) means? Check the perlre(1) man page for explanation of "(??{ code })". As already mentioned, other venues like Perlmonks might serve better for the generic Perl questions. -- Jan Pazdziora

Re: how to run regex calculation

2020-01-09 Thread Wesley Peng
what does (??{$1*$2}) means? Thanks. on 2020/1/9 12:49, Joseph He wrote: I think $str =~ /(\d+)\s(\d+)\s(??{$1*$2})/   should do it My Perl version is  v5.26.1

Re: how to run regex calculation

2020-01-09 Thread demerphq
My apologies you were right. I misunderstood the question. Yves On Thu, 9 Jan 2020, 09:39 demerphq, wrote: > On Thu, 9 Jan 2020 at 05:49, Joseph He wrote: > > > > I think $str =~ /(\d+)\s(\d+)\s(??{$1*$2})/ should do it > > My Perl version is v5.26.1 > > I think you mean (??{ "$1*$2"})

Re: how to run regex calculation

2020-01-09 Thread demerphq
Oh. Heh. I misunderstood the intent. I thought you wanted to match a sequence of digits followed by a space followed by more digits followed by a space followed by the first set of digits repeated 0 or more times followed by the second set of digits. If you want multiplication then Joseph He's

Re: how to run regex calculation

2020-01-09 Thread Wesley Peng
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 =

Re: how to run regex calculation

2020-01-09 Thread demerphq
On Thu, 9 Jan 2020 at 05:49, Joseph He wrote: > > I think $str =~ /(\d+)\s(\d+)\s(??{$1*$2})/ should do it > My Perl version is v5.26.1 I think you mean (??{ "$1*$2"}) which might work, but it will be error prone, (??{"(?$1)*$2") would be better, but both will be slow, as each time a new

Re: how to run regex calculation

2020-01-09 Thread demerphq
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

Re: how to run regex calculation

2020-01-08 Thread Joseph He
I think $str =~ /(\d+)\s(\d+)\s(??{$1*$2})/ should do it My Perl version is v5.26.1 Joseph On Wed, Jan 8, 2020 at 8:36 PM Wesley Peng 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

how to run regex calculation

2020-01-08 Thread Wesley Peng
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.