s*****w 发帖数: 1527 | 1 so in my case, i'm search for pattern $num.num
say $39.88
but the following is not working,
if($i =~ m/\$(.*?)\./)
{
print $1;
}
what's the correct way pls ? |
E*V 发帖数: 17544 | 2 I don't know perl
but usu. reuglar expression is greedy
which means
.* will match every thing unitl the end of the line
【在 s*****w 的大作中提到】 : so in my case, i'm search for pattern $num.num : say $39.88 : but the following is not working, : if($i =~ m/\$(.*?)\./) : { : print $1; : } : : what's the correct way pls ?
|
RR 发帖数: 561 | 3 m/\$(\d*\.\d*)/
【在 s*****w 的大作中提到】 : so in my case, i'm search for pattern $num.num : say $39.88 : but the following is not working, : if($i =~ m/\$(.*?)\./) : { : print $1; : } : : what's the correct way pls ?
|
m*********g 发帖数: 273 | 4 a better way would be
/(\$\d+\.\d+)/ |
d****p 发帖数: 685 | 5 The "?" indicates non-greedy match.
【在 E*V 的大作中提到】 : I don't know perl : but usu. reuglar expression is greedy : which means : .* will match every thing unitl the end of the line
|
d****p 发帖数: 685 | 6 The regex is correct.
Why you say it doesn't work?
【在 s*****w 的大作中提到】 : so in my case, i'm search for pattern $num.num : say $39.88 : but the following is not working, : if($i =~ m/\$(.*?)\./) : { : print $1; : } : : what's the correct way pls ?
|
s*****w 发帖数: 1527 | 7 for 1 line is
$39.88
i got 0 from the print
【在 d****p 的大作中提到】 : The regex is correct. : Why you say it doesn't work?
|
C********s 发帖数: 120 | 8 #!/usr/bin/env perl
use strict;
use warnings;
my $string = q{ $39.88};
if ( $string =~ m/\$(.+)\./ ){
print $1;
}
# ==> 39 |