<pre name="code" class="html"><pre name="code" class="html">perl  跨行匹配;
6.6. Matching Within Multiple Lines
6.6.1. Problem
You want to use regular expressions on a string containing more than one logical line, but the special characters . (any character but newline), ^ (start of string), and $ (end of string) don't seem to work for you. This might happen if you're reading in multiline records or the whole file at once. 6.6.2. Solution
Use /m, /s, or both as pattern modifiers. /s allows . to match a newline (normally it doesn't). If the target string has more than one line in it, /foo.*bar/s could match a "foo" on one line and a "bar" on a following line. This doesn't affect dots in character classes like [#%.], since they are literal periods anyway. 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. 多行匹配 6.6.1 问题 你需要使用正则表达式在一个自付出啊吧 包含多个逻辑行, 但是特定的字符串(任何字符串除了换行) ^ 表示字符串开始 $ 字符串结束 似乎不能为你工作 。 这个可能发生如果你读取多行 记录 6.6.2 解决 使用/m ,/s 或者两者 作为模式修改 /s 允许. 匹配一个换行(通常它不能) 如果目标字符串有多余一行, /foo,*bar/s 可以匹配一个"foo 在一行和一个"bar" 在另外一行 这个不会影响点号 在字符类
the "." metacharacter matches any character except
"\n" (unless you use "/s") /m 修饰符 允许 ^和$来立即匹配 之前和之后一个嵌入的换行符,分别的, /^=head[1-7]/m 会匹配 模式不是在记录的开始,但是任何右边在一个新行 /s 当作一行处理 /s 令 . 匹配换行符并且忽略不建议使用的 $* 变量 /m 令 ^ 和 $ 匹配下一个嵌入的 \n。 zjtest7-frontend:/root# cat a2.pl
my $str="sdgs
sdgdsg
begin
ddd
...
end
d,,,,
sdsdg
begin
sdsg
end ";
if ($str =~/.*?begin.(.*).end/s){
print "\$1 is $1\n";
}; zjtest7-frontend:/root# perl a2.pl
$1 is ddd
...
end
d,,,,
sdsdg
begin
sdsg 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.

												

perl 跨行匹配;的更多相关文章

  1. Perl 正则匹配经验记录

    0.正则匹配字典:http://www.cnblogs.com/itech/archive/2010/03/19/1689793.html 1.$/=">";重新定义字符串分 ...

  2. perl智能匹配

    1.perl中~~为智能匹配,它能够智能地依据符号两側的操作数来确定操作. 如要推断某个元素是否存在于数组中,不使用智能匹配,程序像这样: my $x=2; my @array=(1,2,3); my ...

  3. perl 如何匹配ASCII码以及ASCII码转换

    匹配ASCII码:   /[:ascii:]/ ASCII码转换为数字: ord() 数字转换为ASCII码: chr()

  4. perl 正则匹配多个

    Vsftp:/root# cat k1.pl my $_='upDaTe'; if( $_ =~ /^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK| ...

  5. perl 贪婪匹配小例子

    redis01:/root# cat x2.pl my $str="a19823a456123"; if ($str =~/a(.*)23/){print "1----& ...

  6. perl 正则匹配代码

    36     chomp $line; 37     my @vec = split /\t/, $line; 38     my @vec2 = ($vec[1]=~/[a-z]+/g); 39   ...

  7. Perl正则表达式超详细教程

    前言 想必学习perl的人,对基础正则表达式都已经熟悉,所以学习perl正则会很轻松.这里我不打算解释基础正则的内容,而是直接介绍基础正则中不具备的但perl支持的功能.关于基础正则表达式的内容,可参 ...

  8. 如何用perl将表格中不同列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起

    最近写了一个perl脚本,实现的功能是将表格中其中两列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起. 表格内容如下: 员工号码 员工姓名 职位 入职日期 1001 张三 销售 1980/12/ ...

  9. perl 脚本测试

      原文地址:  http://blog.csdn.net/johnny710vip/article/details/8905239   这是一篇关于perl脚本测试的总结性文章,其中提到了很多实用的 ...

随机推荐

  1. Flink Program Guide (9) -- StateBackend : Fault Tolerance(Basic API Concepts -- For Java)

    State Backends 本文翻译自文档Streaming Guide / Fault Tolerance / StateBackend ----------------------------- ...

  2. Springmvc加载静态文件和开启EL表达式的支持

    一.静态文件加载问题 刚开始学习SpringMVC,发现静态文件无法加载 web.xml配置如下: <web-app id="WebApp_ID" version=" ...

  3. BeyondCompare常用功能图解

    http://jingyan.baidu.com/article/066074d68f847ec3c31cb05a.html http://lovesoo.org/use-file-compariso ...

  4. shell programs

    find * -not -path "docs/*" -regex ".*\.\(rb\)" -type f -print0 | xargs -0     gr ...

  5. android 百度地图定位功能实现

    历经几天时间,终于把定位功能给实现了,可谓是费劲千辛万苦啊,有定位知识还有图层知识,在这里我把代码给大家贴出来,一起分享一下下啦. package com.example.foreveross.off ...

  6. HM中CU,TU的划分

    相信只要是做算法改进的,首先都会遇到这么一个问题:CU,PU及TU这几个在HM中该如何打印出它们最终的划分情况呢?也经常有人来问我这个问题,一般来说,因为问我的时候我一般手头都没有现成的代码可以提供, ...

  7. java.lang.OutOfMemoryError: PermGen space 解决方案

    只需两步: 将值改为512或者1024,然后CTRL+S,重启tomcat 和eclipse即可.

  8. UCS2转UTF-8方法

    前两天工作时需要将UCS2编码转为UTF-8编码在网页显示.网上找了好久没有好方法,后来还是同事给了一个自己的函数,顺利解决问题.把函数贴在这里,愿帮助遇到同样问题的工友们~ /**      * U ...

  9. WildFly8.1(JBoss)+mod_cluster(Apache)群集配置

    继上次使用mod_jk传导Apache+JBoss群集配置后,.因为JBoss5.1启动太慢,于是我开始尝试用最新的WildFly8.1构造(WildFly那是,JBoss.在JBoss7之后改名). ...

  10. Java面试题之Request对象的主要方法

    setAttribute(String name,Object):设置名字为name的request的参数值 getAttribute(String name):返回由name指定的属性值 getAt ...