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