import re
st = 'asxxixxsaefxxlovexxsdwdxxyouxxde'
#search()和 findall()的區別
a = re.search('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st)
#print(a)
#運行結果
#<_sre.SRE_Match object; span=(2, 30), match='xxixxsaefxxlovexxsdwdxxyouxx'>
#group()方法
b = re.search('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st).group(3)
print(b)
#運行結果
#you
c = re.findall('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st)
print(c)
#結果中列表中包含一個元組,只有待匹配字符串中還有
#'xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx'
#例如:
xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx+++xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx
#這種格式的才會有不止一個元組
#運行結果
#[('i', 'love', 'you')]
print(c[0][2])
#運行結果
#you