import re
text = 'banana,appple,banana,orange,123'
print(re.split('[,]+',text))#删除并分开['banana', 'appple', 'banana', 'orange', '123']
print(re.findall('banana',text))#['banana', 'banana']
print(re.search('banana',text))#
print(re.match('bananaa',text))#None
print(re.sub('123','watermelon',text))#banana,appple,banana,orange,watermelon
print(re.escape('www.baidi.com'))#www.baidi.com
print('-'*50)
s = '''
food
water
bad
good
'''
print(re.findall(r'w+',s))
print(re.findall(r'.+',s))
print(re.findall(r'^.+',s))
print(re.findall(r'.+',s,re.S))
print(re.findall(r'.+',s,re.M))#多行模式,不存在n
print('-'*50)
ss = 'apple and banana are delicious'
print(re.findall('\b.+?\b',ss))
print(re.findall(r'bw.+?b',ss))
print(re.findall('\ba.+?\b',ss))
print(re.findall('\Ba.+?\b',ss))
print('-'*50)
#match和search的区别
text1 = 'Shanghai and Guangzhou are beautiful'
a = re.compile(r'bGw+')
print(re.findall(a,text1))
print(re.match(a,text1))#从开头开始寻找,没有就放回None
print(re.search(a,text1))