由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Linux版 - perl regular expression: find $pattern.
相关主题
perl design patternsParrot VM 跑 perl python PHP Ruby 啥意思?
nasty perl syntax minute issues这个perl的简单小程序为什么不work?
一个头痛的regular expression问题网页如何马上更新呢
问道题问问应该学用那个shell?
请教大家一个问题请教个perl/DBI/ssh tunnel的问题
问题:关于python和web[请教]文件输入 (转载)
perl能不能一次把一个str中的a替换成x,b替换成y?how to check space character in perl ?
any bash command option similar as perl -c to check the syn求助,安装PERL 5.8.8 (www.cpan.org)到红帽AS4
相关话题的讨论汇总
话题: pattern话题: perl话题: expression话题: print话题: regular
进入Linux版参与讨论
1 (共1页)
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
1 (共1页)
进入Linux版参与讨论
相关主题
求助,安装PERL 5.8.8 (www.cpan.org)到红帽AS4请教大家一个问题
crontab的一个小问题问题:关于python和web
c/c++, R, perl这些你们平时用的多马?perl能不能一次把一个str中的a替换成x,b替换成y?
unix下运行perl输出.txt文件any bash command option similar as perl -c to check the syn
perl design patternsParrot VM 跑 perl python PHP Ruby 啥意思?
nasty perl syntax minute issues这个perl的简单小程序为什么不work?
一个头痛的regular expression问题网页如何马上更新呢
问道题问问应该学用那个shell?
相关话题的讨论汇总
话题: pattern话题: perl话题: expression话题: print话题: regular