import re
import re
a = re.match(r'^(\d{2})','1')
b = re.match(r'^(\d{2})','12')
c = re.match(r'^(\d{4})-(\d{2})-(\d{2})$','2018-11-12')
d = re.match(r'a{3}','aa')
e = re.match(r'a{3}','aaa')print("a match: {}".format(a))print("b match: {}".format(b))print("c match: {}".format(c))print("c match: {}".format(c.span()))print("c match: {}".format(c.start()))print("c match: {}".format(c.end()))print("c match: {}".format(c.group()))print("d match: {}".format(d))print("e match: {}".format(e))
结果
a match: None
b match: <_sre.SRE_Match object; span=(0, 2), match='12'>
c match: <_sre.SRE_Match object; span=(0, 10), match='2018-11-28'>
c match: (0, 10)
c match: 0
c match: 10
c match: 2018-11-28
d match: None
e match: <_sre.SRE_Match object; span=(0, 3), match='aaa'>