由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - Regular expression
相关主题
[转载] UNIX下的strtokRegular expression的问题
[转载] 一个简单的regular expression问题question about token ring...
[转载] Re: 一个简单的regular expression问题[转载] [Q] sh under Redhat9.0
regular expression中回车用什么表示?[转载] 新手问perl的初级问题
Regular ExpressionsRe: How to compare two binary files in Unix?
[转载] Help with Perl Regular Expression[转载] C 语言输入函数紧急求助!
regular expression questionwhat is the differnece between const char * and..
regular expessions in viabout strtok()
相关话题的讨论汇总
话题: line话题: regular话题: token话题: expression话题: print
进入Unix版参与讨论
1 (共1页)
f***y
发帖数: 98
1
#!/usr/bin/perl
$line = "one two three...";
print "$line\n";
$line =~ s/^([^ ]+) +([^ ]+)/$2 $1/;
print "$line\n";
w*****n
发帖数: 94
2

[^ ] stands for one char which is not space.
the third line reads like: find a token (one or more non space chars),
one or more spaces, and another token, and change them to the second
token ($2), space and the first token ($1).
+ stands for one or more, () are used to capture, everything matched
in the first () is stored in $1, $2 for the second (). BTW, the ^ at
the beginning of RE stands for match beginning of the string ($line).
get a perl book or "man perlre" for details.

【在 f***y 的大作中提到】
: #!/usr/bin/perl
: $line = "one two three...";
: print "$line\n";
: $line =~ s/^([^ ]+) +([^ ]+)/$2 $1/;
: print "$line\n";

1 (共1页)
进入Unix版参与讨论
相关主题
about strtok()Regular Expressions
[转载] 紧急求教一个技术问题 unix c[转载] Help with Perl Regular Expression
请回答一下9176regular expression question
True 64移植档AIX5L 的问题regular expessions in vi
[转载] UNIX下的strtokRegular expression的问题
[转载] 一个简单的regular expression问题question about token ring...
[转载] Re: 一个简单的regular expression问题[转载] [Q] sh under Redhat9.0
regular expression中回车用什么表示?[转载] 新手问perl的初级问题
相关话题的讨论汇总
话题: line话题: regular话题: token话题: expression话题: print