python里使用正则表达式的内嵌功能选项标志
2017-11-05 13:23
369 查看
在前面学习过正则表达式有一些标志,可以通过编译时添加进去。比如学习过的re.DOTALL标志,这些标志都是在编译设置的,如果不是立即编译正则表达式时,就不能使用这些参数。比如你需要把一个正则表达式当作参数传送给别的函数时,就比较麻烦,不仅要传送正则表达式,还需要传送选项标志。如果开发人员不小心,把一个参数搞丢了,或者搞错了,就容易出错,这时怎么办呢?显然有更好的方式,就是把选项参数融入正则表达式里,这样就达到原子一致性,要丢就一起丢,不会出现半桶水的样子。如下面例子:
结果输出如下:
Text : This is some text -- with punctuation.
Pattern : \bT\w+
Matches : ['This']
(?i):
Text : This is some text -- with punctuation.
Pattern : (?i)\bT\w+
Matches : ['This', 'text']
在这个例子里,就是添加(?i)在正则表达式里面表示不对大小字母敏感。
标志 对应的字母
ASCII a
IGNORECASE i
MULTILINE m
DOTALL s
VERBOSE x
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6 #蔡军生 #http://blog.csdn.net/caimouse/article/details/51749579 # import re text = 'This is some text -- with punctuation.' pattern = r'\bT\w+' regex = re.compile(pattern) print('Text :', text) print('Pattern :', pattern) print('Matches :', regex.findall(text)) print('\n(?i):') pattern = r'(?i)\bT\w+' regex = re.compile(pattern) print('Text :', text) print('Pattern :', pattern) print('Matches :', regex.findall(text))
结果输出如下:
Text : This is some text -- with punctuation.
Pattern : \bT\w+
Matches : ['This']
(?i):
Text : This is some text -- with punctuation.
Pattern : (?i)\bT\w+
Matches : ['This', 'text']
在这个例子里,就是添加(?i)在正则表达式里面表示不对大小字母敏感。
标志 对应的字母
ASCII a
IGNORECASE i
MULTILINE m
DOTALL s
VERBOSE x
深入浅出Numpy
http://edu.csdn.net/course/detail/6149
Python游戏开发入门
http://edu.csdn.net/course/detail/5690你也能动手修改C编译器
http://edu.csdn.net/course/detail/5582纸牌游戏开发
http://edu.csdn.net/course/detail/5538
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
相关文章推荐
- python里使用正则表达式的内嵌功能选项标志
- python里使用正则表达式的词组匹配功能
- python里使用正则表达式排除集合里字符的功能
- 详解python里使用正则表达式的全匹配功能
- python使用正则表达式的search()函数实现指定位置搜索功能
- python里使用正则表达式的选项参数
- python里使用正则表达式的全匹配功能
- python里使用正则表达式的DOTALL标志
- python里使用正则表达式的限制边界功能
- Python天天美味(15) - Python正则表达式操作指南(re使用)(转)
- Python正则表达式操作指南(re使用)(转)
- python使用带汉字的正则表达式
- [转]使用python的正则表达式做词法分析器
- Python使用正则表达式替换源码前序号
- 使用sqlserver"查找和替换"的正则表达式和通配符功能
- 【语言处理与Python】3.4使用正则表达式检测词组搭配
- 使用python和正则表达式获取url,及总结
- python 学习记录(2)—re 正则表达式模块的使用
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- 条款二十九:使用正则表达式的捕获功能