perl /m修饰符使用说明

高级用法;
多行匹配:

grok正则和普通正则一样, 默认是不支持匹配回车换行的。


perl的/m选项

The /m modifier allows ^ and $ to match immediately before and after an embedded newline, 


respectively. /^=head[1-7]/m would match that pattern not just at the beginning of the record, but anywhere right after a newline as well.



/m 修饰符允许 ^和$来立即匹配之前和之后的一个嵌入式的换行,

分别的. /^=head[1-7]/m 会匹配 模式不只是在记录的开始,但是任何地方在一个新行之后


[tomcat@wx02 test]$ cat a3.pl 
my $str="=head1
abc
2";
 if ($str =~/^=head[1-7]\nabc\n2/m){print "1111111111\n"};
[tomcat@wx02 test]$ perl a3.pl 
1111111111


m 是将字符串作为多行处理,s是将字符串作为单行处理,如果是s在字符串中出现的\n就相当于普通字符。

m将串视为多行
o只赋值一次
s将串视为单行

posted @ 2016-08-19 10:21  czcb  阅读(173)  评论(0编辑  收藏  举报