In [2]: ma=re.match(r'<([\w]+>)[\w]*</\1','<book>python</book>') #\1代表前面括号内模式,重复匹配
In [3]: ma.group()
Out[4]: '<book>python</book>'
#匹配重复的字符
>>> p = re.compile(r'(\b\w+)\s+\1')#\1代表前面括号内模式,重复匹配
>>> p.search('Paris in the the spring').group()
'the the'