<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. 第二章——Parcelable接口的使用(跨进程,Intent传输)

    一.Parcelable类(Android独有的) 简介:Parcelable是一个接口. 作用:是Android提供的序列化接口,实现序列化和反序列化的操作. 二.跨进程使用 步骤一:创建Book类 ...

  2. XCode: Target Settings和Project Settings的区别

    一个XCode project包含了两种设置:Project Settings 和 Target Settings. 它们之间的主要区别在于:Project settings应用于project里面的 ...

  3. error: ld returned 1 exit status 和 error:undefined reference

    undefined reference 往往是链接时出现错误,无法解析引用.这篇文章总结的很好undefined reference问题总结 error: ld returned 1 exit sta ...

  4. 借助bootstrap框架模仿airbnb写的网页

    View HTML .nav a { color: #5a5a5a; font-size: 11px; font-weight: bold; padding: 14px 10px; text-tran ...

  5. c++ string.find()函数的陷阱

    string.find(char *)查找字符串中是否包含子串 找到:返回第一个索引 没有找到:返回一个很大的随机数字而不是返回负数(这是个坑) 所以不能这么写if (string.find(str) ...

  6. 使用Vitamio打造自己的Android万能播放器(3)——本地播放(主界面、播放列表)

    前言 打造一款完整可用的Android播放器有许多功能和细节需要完成,也涉及到各种丰富的知识和内容,本章将结合Fragment.ViewPager来搭建播放器的主界面,并实现本地播放基本功能.系列文章 ...

  7. Java面试题之J2EE是什么

    J2EE是Sun公司提出的多层(multi-diered),分布式(distributed),基于组件(component-base)的企业级应用模型(enterpriese application ...

  8. 浅谈C++中指针和引用的区别

    指针和引用在C++中很常用,但是对于它们之间的区别很多初学者都不是太熟悉,下面来谈谈他们2者之间的区别和用法. 1.指针和引用的定义和性质区别: (1)指针:指针是一个变量,只不过这个变量存储的是一个 ...

  9. tomcat 配置项目

    tomcat\conf\Catalina\localhost      下面存在项目配置文件信息,emas.xml 表示你eclipse中有个emas项目, 还有其他的项目xml.

  10. Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)

    1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...