#_author:Star
#date:2019/11/8
#正则表达式的方法
#1. findall()-->所有的结果都返回到一个列表里
#2. search()--->返回匹配到的第一个对象,对象可以调用group()方法返回结果
#3. match()--->只在字符串开始匹配,,对象可以调用group()方法返回结果
import re
ret=re.match('star','gejhstar')
print(ret)# None
ret1=re.match('star','stargejh')
print(ret1)# <re.Match object; span=(0, 4), match='star'>
print(ret1.group()) # star
#4.split
ret2=re.split('m','asmagd')
print(ret2)#['as','agd']
ret3=re.split('[m,d]','asmagdoku') # ********
print(ret3)# ['as', 'ag', 'oku']
ret4=re.split('[m,d]','madgdoku') # ********
print(ret4)# ['', 'a', 'g', 'oku'] 有 空是因为第一个m前面没有字母
#5.sub()
ret5=re.sub('s..r','good','comestarup')# -------->important
print(ret5)# comegoodup
#6.compile() 编译
mat0=re.findall('.com','idhdiwwhi.comjdj')
print(mat0) # ['.com']
obj=re.compile('.com')
mat=obj.findall('idhdiwwhi.comjdj')
print(mat)# ['.com']