首页 > 编程语言 > 详细

python正则表达式 ---- re模块

时间:2017-08-06 18:39:43      阅读:203      评论:0      收藏:0      [点我收藏+]

1.正则表达式

  正则就是使用一些具有特殊含义的符号组合到一起,来描述字符串或字符的方法。

2.常用的正则匹配模式

技术分享

import re
print
(re.findall(‘\w‘,‘hello_ | egon 123‘)) #匹配字母数字下划线 print(re.findall(‘\W‘,‘hello_ | egon 123‘)) #与小w相反 匹配非数字字符下划线 print(re.findall(‘\s‘,‘hello_ | egon 123 \n \t‘)) #匹配任意空白字符如 [ \t,\n,\r,\f] print(re.findall(‘\S‘,‘hello_ | egon 123 \n \t‘)) #与小s相反匹配任意分空白字符 print(re.findall(‘\d‘,‘hello_ | egon 123 \n \t‘)) #匹配任意数字 print(re.findall(‘\D‘,‘hello_ | egon 123 \n \t‘)) #匹配任意非数字 print(re.findall(‘h‘,‘hello_ | hello h egon 123 \n \t‘)) #匹配字符 print(re.findall(‘\Ahe‘,‘hello_ | hello h egon 123 \n \t‘)) #匹配字符串的开头 等同与^ print(re.findall(‘^he‘,‘hello_ | hello h egon 123 \n \t‘)) # # print(re.findall(‘123\Z‘,‘hello_ | hello h egon 123 \n \t123‘)) #匹配字符串的结尾,存在换行,只匹配到换行前的结束字符串。 print(re.findall(‘123\z‘,‘hello_ | hello h egon 123 \n \t123‘)) #匹配字符串结尾 等同于$ print(re.findall(‘123$‘,‘hello_ | hello h egon 123 \n \t123‘)) print(re.findall(‘\n‘,‘hello_ | hello h egon 123 \n \t123‘)) #匹配一个换行符 print(re.findall(‘\t‘,‘hello_ | hello h egon 123 \n \t123‘)) #匹配一个制表符

 

python正则表达式 ---- re模块

原文:http://www.cnblogs.com/yxwang/p/7295509.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!