随笔分类 -  正则表达式

摘要:一次更新多个文件 阅读全文
posted @ 2013-09-18 11:19 新闻官
摘要:无损替换 /r 阅读全文
posted @ 2013-09-18 10:34 新闻官
摘要:Perl 捕获变量 阅读全文
posted @ 2013-09-16 10:36 新闻官
摘要:Perl5 的锚位 阅读全文
posted @ 2013-09-16 09:55 新闻官
摘要:模式匹配修饰符 阅读全文
posted @ 2013-09-16 09:20 新闻官
摘要:模式测试程序 阅读全文
posted @ 2013-09-13 11:15 新闻官
摘要:对于常见的问题,其实早有人写好通用模式,做成漂亮的Regex::Common 模块放在CPAN上。Regexp::Common::balancedProvides regexes for strings with balanced parenthesized delimiters.Regexp::Common::commentProvides regexes for comments of various languages (43 languages currently).Regexp::Common::delimitedProvides regexes for delimited stri 阅读全文
posted @ 2013-04-15 10:25 新闻官
摘要:内容略,评测代码如下:open my $fh, "<", "$Bin/res/apache.log" or die "apache.log: $!";my @data=<$fh>;timethese( 10000000, { 'Common IP' => q{ foreach(@data) { my ($ip) = m/^($RE{net}{IPv4})/; } }, 'Person IP1' => q{ foreach(@data) { ... 阅读全文
posted @ 2013-04-09 16:23 新闻官
摘要:预编译正则表达式 阅读全文
posted @ 2013-04-08 08:30 新闻官
摘要:仅编译正则表达式一次 阅读全文
posted @ 2013-04-07 08:47 新闻官
摘要:避免不必要的回溯 阅读全文
posted @ 2013-04-07 08:40 新闻官
摘要:提高正则表达式的可读性 阅读全文
posted @ 2013-04-07 08:26 新闻官
摘要:简单字符串处理应避免使用正则表达式 阅读全文
posted @ 2013-04-01 16:20 新闻官
摘要:1. 用\b判断单词边界注意:在写正则表达式时,如果将\w与\s或者\W 与\S连用,就有可能出现问题。如果一定要用,至少先检查仔细my ($user,$tty) = /(\S+)\s+(\S+)/; #匹配who输出内容提取用户名陈和终端名称如果不确定\b和\B会在何处匹配,试着用替换操作将这些地方标出来:my $text = q(What's a "word" boundary?);(my $btext = $text) =~ s/\b/:/g;(my $Btext = $text) =~s/\B/:/g;2.用^或\A匹配起始位置^通常用来匹配字符串的起始位置 阅读全文
posted @ 2013-04-01 15:42 新闻官
摘要:能懒则懒,不要贪婪 阅读全文
posted @ 2013-03-29 10:12 新闻官
摘要:小心处理匹配变量 阅读全文
posted @ 2013-03-27 09:45 新闻官
摘要:仅需分组时,用非捕获括号 阅读全文
posted @ 2013-03-27 09:21 新闻官
摘要:使用命名捕获,给匹配加标签 阅读全文
posted @ 2013-03-27 08:43 新闻官
摘要:使用更精确的空白字符组 阅读全文
posted @ 2013-03-26 09:25 新闻官
摘要:正则表达式的捕获功能 阅读全文
posted @ 2013-03-26 08:52 新闻官