>>>import re
>>> m = re.match('stu','student')>>> m.group()'stu'>>>n = re.match('tu','student')>>>type(n)<class'NoneType'>```
>>> m = re.match('(\w\w\w)-(\d\d\d)','abc-123')>>> m.group(1)'abc'>>> m.group(2)'123'>>> m.groups()('abc','123')
>>> s ='This and that'>>> re.findall('(th\w+) and (th\w+)',s,re.I)[('This','that')]>>>re.finditer('(th\w+) and (th\w+)',s,re.I).next().groups()('This','that')
>>> re.sub('[ae]','X','abcdefg')'XbcdXfg'
>>>html ='<div><span>this is span</span><a>this is a</a></div>'>>>result = re.findall('<span>(.*?)</span><a>(.*?)</a>',html)>>>print(result)>>>[('this is span','this is a')]>>>#将正则表达式定义为一个对象>>>com = re.compile("<span>(.*?)</span><a>(.*?)</a>")>>>text = re.findall(com,html)>>>print(text)>>>[('this is span','this is a')]