python里使用正则表达式的内嵌功能选项标志
来源:互联网 发布:广州疯狂java在哪 编辑:程序博客网 时间:2024/06/11 00:32
在前面学习过正则表达式有一些标志,可以通过编译时添加进去。比如学习过的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+
标志 对应的字母
ASCII a
IGNORECASE i
MULTILINE m
DOTALL s
结果输出如下:
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
宁波整形美容医院 http://www.lyxcl.org/
阅读全文
0 0
- python里使用正则表达式的内嵌功能选项标志
- python里使用正则表达式的内嵌功能选项标志
- python里使用正则表达式的MULTILINE标志
- python里使用正则表达式的DOTALL标志
- python里使用正则表达式的选项参数
- python里使用正则表达式的限制边界功能
- python里使用正则表达式的全匹配功能
- python里使用正则表达式的词组匹配功能
- python里使用正则表达式排除集合里字符的功能
- python里使用正则表达式
- python里使用正则表达式的转义字符的匹配
- python里使用正则表达式的重复模式
- python里使用正则表达式的非贪婪模式
- python里使用正则表达式的集合字符
- python里使用正则表达式的连接符
- python里使用正则表达式的句号和星号
- python里使用正则表达式的预先定义集合字符
- python里使用正则表达式的边界符进行匹配
- 【CSS】文字属性的一些总结
- CSRF攻击与防御
- B、B+树
- logback 生成日志时日志名称为XXX_IS_UNDEFINED
- unity关于android打包性能设置
- python里使用正则表达式的内嵌功能选项标志
- 1句运营心法,8个核心词汇读懂运营
- 大数模板
- python圣斗士修炼(十二):给你介绍个对象!
- OkHttp封装
- 接口又多又杂怎么办?试试用eolinker轻松管理API接口文档
- Eclipse进行远程调试linux 环境的tomcat配置
- HttpClient通过post上传文件和提交参数
- Linux内核编译安装