perl 跨行匹配;
<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 跨行匹配;的更多相关文章
- Perl 正则匹配经验记录
0.正则匹配字典:http://www.cnblogs.com/itech/archive/2010/03/19/1689793.html 1.$/=">";重新定义字符串分 ...
- perl智能匹配
1.perl中~~为智能匹配,它能够智能地依据符号两側的操作数来确定操作. 如要推断某个元素是否存在于数组中,不使用智能匹配,程序像这样: my $x=2; my @array=(1,2,3); my ...
- perl 如何匹配ASCII码以及ASCII码转换
匹配ASCII码: /[:ascii:]/ ASCII码转换为数字: ord() 数字转换为ASCII码: chr()
- perl 正则匹配多个
Vsftp:/root# cat k1.pl my $_='upDaTe'; if( $_ =~ /^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK| ...
- perl 贪婪匹配小例子
redis01:/root# cat x2.pl my $str="a19823a456123"; if ($str =~/a(.*)23/){print "1----& ...
- perl 正则匹配代码
36 chomp $line; 37 my @vec = split /\t/, $line; 38 my @vec2 = ($vec[1]=~/[a-z]+/g); 39 ...
- Perl正则表达式超详细教程
前言 想必学习perl的人,对基础正则表达式都已经熟悉,所以学习perl正则会很轻松.这里我不打算解释基础正则的内容,而是直接介绍基础正则中不具备的但perl支持的功能.关于基础正则表达式的内容,可参 ...
- 如何用perl将表格中不同列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起. 表格内容如下: 员工号码 员工姓名 职位 入职日期 1001 张三 销售 1980/12/ ...
- perl 脚本测试
原文地址: http://blog.csdn.net/johnny710vip/article/details/8905239 这是一篇关于perl脚本测试的总结性文章,其中提到了很多实用的 ...
随机推荐
- Python 自学笔记(二)第一个程序 Hello World
一 打印 Hello world 1,输入 Python “Hello world” 即可 2,脚本文件输出Hello World 在命令行(cmd),输入 python 文件路径+文件名 3,为什么 ...
- 一些常用的JS函数
//获取元素属性 function getStyle(obj, attr) { return obj.currentStyle ? obj.currentStyle[attr] : getComput ...
- 【自学php】第三天 - 读写文件
这次的例子是把订单的数据保存起来,一般是用数据库来进行数据的存储最好,但是今天目的是为了学习读写文件,所以这次把数据存在文件里. 读写文件有一般有三个步骤: 1)打开文件.如果文件不存在,需要先创建它 ...
- 第二章 andrid studio创建项目
原文 http://blog.csdn.net/zhanghefu/article/details/9326735 第二章 andrid studio创建项目 第二章 andrid studio创建项 ...
- 只有电信3G是公网ip。
只有电信3G是公网ip,其它网络拿到是内部网.
- 元数据(meta-data)
本章所介绍的元数据的知识,可能在定制系统时会用到.因为那是后需要修改底层框架的一些内容 一.元数据的定义 在AndroidManifest.xml中如下书写: <activity android ...
- JScript中的prototype(原型)属性研究
今天看到同事使用js中的Prototype,感觉很是新鲜.由此想深入学习一下prototype(英['prəʊtətaɪp] 美['protə'taɪp]n. 原型:标准,模范),在学习prototy ...
- C#中dynamic的正确用法【转】
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- hadoop中汉字与英文字符混合的keyword做为combine的key的问题
近期,须要将汉字与字符的非常合串作为combine的输出的key, 这样做是希望,利用hadoop的归并来依照key进行分组,然后,在reduce阶段,拿到的都是一个一个组. 可是,发现,这样的,汉字 ...
- checkbox和radio的样式美化问题
如果你下定决心要改变现有的默认的checkbox和radio的样式,那么我目前有两种办法: 1.自己动手写一个,也就是自己写代码实现将input的checkbox和radio默认的样式隐藏掉,使用绝对 ...