标题: 正则表达式疑问 [打印本页] 作者: 772546116 时间: 2019-3-12 21:20 标题: 正则表达式疑问 import re
text='Let us go go go !'
m=re.findall('(go\s*)+',text)
if m:
print m
else:
print 'not match'
# 实战检测一下更好理解
print(2, '---------------------------------------')
text = 'Let us 3 4 5 52 go go go !'
m1 = re.findall('(\d+?)', text)
m2 = re.findall('(\d+)', text)
m3 = re.findall('(5\d*?)', text)
print(m1)
print(m2)
print(m3)
# 3
"""
\s 匹配任意空白字符,等价于 [\t\n\r\f].
\s*
\s*?
从上边可以发现, *、*?和上边意义也一样,只是这里\s匹配空字符
"""
print(3, '---------------------------------------')
text = 'Let us go go go !'
m1 = re.findall(r'go\s+', text)
m2 = re.findall(r'go\s+?', text)
m3 = re.findall(r'go\s*?', text)