2018-05-03Python:正则表达式

1.用法:使用Python的re模块,首先用re.compile() 函数,将正则表达式的字符串形式编译为Pattern实例,然后通过Pattern实例处理文本并获得匹配结果(Match实例),再通过Match实例做其他操作。

2.re模块中的match方法:只匹配字符串开始处的字符。3.re模块中的search方法:会匹配整个字符串。'''

# 1

pattern = re.compile('[a-zA-Z]')

match = pattern.findall('ddhfsaqugfa3412hdh21hhdGAAASAA')

print(match)

# 2

print(re.match('\d0','30ddd'))

# 3

print(re.search('\d0','ddd30ddd40ffff50hhh'))

你可能感兴趣的:(2018-05-03Python:正则表达式)