perl学习之:匹配修饰符/s /m
m 是将字符串作为多行处理,s是将字符串作为单行处理,如果是s在字符串中出现的\n就相当于普通字符。 |
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.
最新文章
- 常见的特殊字符和HTML之间的对应关系~
- nyoj 712 探 寻 宝 藏--最小费用最大流
- iOS - Swift 	命令行输入输出
- nignx+php-fpm环境下 phpmyadmin打开空白的原因探究
- [020] Android模拟器访问本地Web应用
- Shell统计报表表格生成
- 配置servers时,错误:Setting property 'source' to 'org.eclipse.jst.jee.server:hczm' did not find a matching property
- System.Web.Http.Tracing 在webapi里面应用
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
- python网络爬虫之LXML与HTMLParser
- spring实例化dataSource使用jndi和jdbc两种方式
- Anaconda的安装与使用
- 002_监测ssl证书过期时间
- 梯度下降取负梯度的简单证明,挺有意思的mark一下
- OpenStack 安装:keystone服务
- c# Datatable导出Excel
- POJ 3017 Cut the Sequence
- usaco 洛谷 P2694 接金币 题解
- ios中Pldatabase的用法
- POJ1179 Polygon
热门文章
- JAVA团队开发手册 - 3. 开发流程
- Turtles (非纯分块)
- 51nod 1562 玻璃切割 (set)
- ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
- dzzoffice 任意文件删除漏洞分析
- POJ1470 LCA (Targan离线)
- 安装linux时的分区问题,需要了解目录树及挂载知识
- REST访问(RestTemplate)
- 使用JOSM编辑OpenStreetMap地图
- SAP Cloud for Customer(C4C)的一些学习资料