<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. javac编译原理(一)

    我们都知道,计算机只能识别二进制语言,是不能直接识别java c c++等高级语言的.将高级语言转化成计算机可以是别的二进制语言,这个过程就叫编译. 有次面试,面试官问了一道“java的编译原理是什么 ...

  2. oracle group by 使用

    SELECT supplier_id, max(evidence_date) AS evidence_date,max(TD_SUPPLIER_EVIDENCE_INFO_ID) AS TD_SUPP ...

  3. Hive的安装配置

    Hive的安装配置 Hive的安装配置 安装前准备 下载Hive版本1.2.1: 1.[root@iZ28gvqe4biZ ~]# wget http://mirror.bit.edu.cn/apac ...

  4. Spring随笔 - 事务传播行为

    Spring定义了7种不同的事务传播行为: PROPAGATION_MANDATORY:表示该方法必须在事务中运行.如果当前事务不存在,则会抛出一个异常. PROPAGATION_NESTED:表示如 ...

  5. $.Event 你不知道的用法

    最近在使用Bootstrap.js,一不小心趴开源码看了一下,尤其是看到tab.js var hideEvent = $.Event('hide.bs.tab', { relatedTarget: $ ...

  6. MySQL恢复备份读书笔记

    1. 任何执行时间长于 wait_timeout或interactive_timeout选项值得备份,都会导致会话被关闭,这也会隐含执行UNLOCK TABLES命令.2. 对于使用FLUSH TAB ...

  7. 一元云购qq互联回调地址错误解决办法

    经过追踪,点击登录后调用 system/modules/api/下面的qqlogin.action.class.php 里面又调用了qq 互联php接口样例里的QC.php的QC类的方法qq_logi ...

  8. Windows 打开防火墙上的指定端口

    第一步: 控制面板-->打开防火墙 第二步: 高级设置 第三步: 入站规则--->新建规则 第四步: 第五步: 第六步: 第七步: 第八步:

  9. jQuery学习-事件之绑定事件(四)

    今天我们来学习jQuery.Event对象.jQuery为了添加自己的处理机制,及可以传递用户自定义数据,于是Event对象就出世了.   1 jQuery.Event = function( src ...

  10. 一封在JSP课程结束之后给学生的信

    <JSP应用程序设计>这门课终于考完了,虽然题目有点难,但我看大部分同学考的还可以,算上平时成绩应该都能拿到一个满意的分数. 再次感谢大家一个学期来对我的支持,跟大家一起的这个学期很开心, ...