ITeye博客

perl 正则表达式

luogen33 · 2011-11-25 14:04 · 编程语言 · Markdown

正则表达式: $scalarName =~ s/a/b; # substitute the character a for b, and return true if this can happern $scalarName =~ m/a; # does the scalar $scalarName have an a in it? $scalarName =~ tr/A-Z/a-z/; # translate all capital letter with lower case ones, and return ture if this happens $scalarName !~ s/a/b/; # substitute the character a for b, and return false if this indeed happens. $scalarName !~ m/a/; # does the scalar $scalarName match the character a? Return false if it does. $scalarName !~ tr/0-9/a-j/; # translate the digits for the letters a thru j, and return false if this happens.

#!/usr/bin/perl $mt="abcdeFGhigk"; #匹配 if ($mt =~ m/Fg/i){ print "匹配--it is matched ! \n";

}

替换

if ($mt=~s/FG/fg/){ print "替换-- $mt \n"; } #转换 if ($mt =~ tr///){ print "转换--$mt \n"; }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。