Master Regular Expressions 2nd Edition(二)
来源:互联网 发布:刺客知伯 编辑:程序博客网 时间:2024/05/19 04:53
修改文本
1、Perl中的替换表达式为:
$var =~ s/regex/replacement/
可以在replacement中使用$1等变量
2、Perl中<>表示一行文本
3、definded($val)查看一个变量是否有定义
4、lookaround:定位标识,定位到匹配文本位置之前或之后
lookahead(定位在前):(?=...)
lookback(定位在后):(?<=...)
5、/g选项表示global replacement,全部替换
6、s/(?<=/bJeff)(?=s/b)/'/g
搜索一个位置,这个位置前面是Jeff,后面是s,然后在这个位置上加'
7、s/(?=s/b)(?<=/b Jeff)/'/g 和 s/(?<=/bJeff)(?=s/b)/'/g 表达了同一个位置
8、给整数每三位加上一个逗号,比如123456789变成123,456,789
$pop =~ s/(?<=/d)(?=(/d/d/d)+$)/,/g;
或者
(?<=/d)(?=(?:/d/d/d+$)
其中多加了(?:...)表示不参与子匹配,更有效率,但相对复杂难懂
$pop =~ s/(?<=/d)(?=(/d/d/d)+(?!/d))/,/g;才是正确的,晕。原因是$,所以使用Negative Lookahead来替换
9、位置匹配的四种情况:
Type Regex Successful if the enclosed subexpression . . .
Positive Lookbehind (?<=......) successful if can match to the left
Negative Lookbehind (?<!......) successful if can not match to the left
Positive Lookahead (?=......) successful if can match to the right
Negative Lookahead (?!......) successful if can not match to the right
- Master Regular Expressions 2nd Edition(二)
- Master Regular Expressions 2nd Edition(一)
- Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET, 2nd edition
- Memories of 《Mastering Regular Expressions》3rd Edition
- 读书笔记《Mastering Regular Expressions》(二)
- 《Java Swing》2nd Edition
- Hacking Exposed - 2nd Edition
- Programming C# (2nd Edition)
- Programming C# (2nd Edition)
- 《Programming Pearls》 2nd Edition
- Software Testing (2nd Edition)
- Google Hacks, 2nd Edition
- Access Cookbook, 2nd Edition
- Understanding .NET (2nd Edition)
- Professional Ajax, 2nd Edition
- PHP Essentials, 2nd Edition
- XML Bible (2nd Edition)
- Effective Java (2nd Edition)
- 【传道授业解惑】关于毕业设计开发环境
- 实现文本自动分类的基础----Term频率计算方法
- 交换数据流(ADS)与IIS的前世与今生
- 澳门赌场输钱记 500HK。
- 用vb实现ftp的上传下载
- Master Regular Expressions 2nd Edition(二)
- 这种女人是值得每个男人为之珍惜一辈子
- ASP简单防盗链
- 研发冲突管理(1)----不是唯市场说了算
- EI全文数据库
- 用Asp+XmlHttp实现RssReader功能
- Eiffel初探(基于合约的编程方式)
- 记住你只能活一辈子
- 21世纪如何正确思考及开创个人事业(转发)