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 col
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 t
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
$result="false";$result="true
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 1)
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(\
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
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
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"}) which
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 orig
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
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 patte
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 2
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 say
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.
14 matches
Mail list logo