perl 跨行匹配;
来源:互联网 发布:少儿编程课程 编辑:程序博客网 时间:2024/06/05 11:16
<pre name="code" class="html"><pre name="code" class="html">perl 跨行匹配;6.6. Matching Within Multiple Lines6.6.1. ProblemYou 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. SolutionUse /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="sdgssdgdsgbeginddd...end d,,,,sdsdgbegin sdsgend ";if ($str =~/.*?begin.(.*).end/s){ print "\$1 is $1\n"; }; zjtest7-frontend:/root# perl a2.pl $1 is ddd...end d,,,,sdsdgbegin sdsgThe /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.
0 0
- perl 跨行匹配;
- perl 跨行匹配文件内容 双层过滤
- [perl] 一句命令进行跨行匹配替换
- perl中的多行匹配问题
- perl实现多行模式匹配
- Perl 取匹配行的下一行
- Perl模式匹配
- perl 模式匹配总结
- perl正则匹配
- Perl匹配中文
- Perl 模式匹配
- perl 模式匹配
- perl中的模式匹配
- Perl匹配中文
- perl(1) 匹配数字
- perl字符匹配
- perl 模式匹配
- perl 5 智能匹配
- Maven那点事儿
- spark源码编译后记
- Java 集合系列02之 Collection架构
- iframe中弹出框后添加覆盖整个页面的遮罩层并且不覆盖子页面中的弹出框
- Java的构造方法
- perl 跨行匹配;
- linux中pid,tid, 以及 真实pid的关系
- 中断一、外部中断
- pyinstaller使用
- 《零基础学习软件测试》之LoadRunner从入门到精通
- viser_1
- redis的安装与使用
- Spark-Sql源码解析之二 Sqlparser:sql –> unresolved logical plan
- 仿支付宝支付密码输入框功能