码迷,mamicode.com
首页 > 编程语言 > 详细

python正则表达式

时间:2017-06-26 17:06:49      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:dal   log   执行   结果   python   color   []   find   style   

元字符 . ^ $ * + ? {} [] | () \

. 匹配除换号符以为的任意一个符号

ret=re.findall(‘李.‘,‘李杰,李刚,王超,占山,李莲英‘)
print(ret)
执行结果
[‘李杰‘, ‘李刚‘, ‘李莲‘]
ret2=re.findall(‘李..‘,‘李杰,李刚,王超,占山,李莲英‘)
print(ret2)
执行结果
[‘李杰,‘, ‘李刚,‘, ‘李莲英‘]

^ 以指定字符开头

ret3=re.findall(‘^李.‘,‘yuan李杰,李刚,王超,占山,李莲英‘)
print(ret3)
执行结果
[]

$ 以指定字符结尾

ret=re.findall(‘英$‘,‘yuan李杰,李刚,王超,占山,李莲英‘)
print(ret)
执行结果
[‘英‘]

python正则表达式

标签:dal   log   执行   结果   python   color   []   find   style   

原文地址:http://www.cnblogs.com/c491873412/p/7081110.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!