import re
phone='62589999'
regex=r'd{4}(d)r{3}' #r'...()...()...()..'
print(re.match(regex,phone))
print(re.match(regex,phone).groups())
print(re.match(regex,phone).group())
print(re.match(regex,phone).group(0))
print(re.match(regex,phone).group(1))
'''
以下代码有问题:
出现了下标越界的异常:IndexError
原因为正则中只有1个子组,没有index=2这一说,所以报错了...
'''
# print(re.match(regex,phone).group(2))
phone = '021-52184329'
regex = r'(?P<one>d{3})(?P<two>-)(?P<three>d{8})'
mathobj=re.search(regex,phone)
print(mathobj.groups())
print(mathobj.group())
print(mathobj.group(0))
print(mathobj.group('one'))