import re # python爬虫电话号码匹配识别提取 phone = '020-68886888' result = re.match(r'(\d{3}|\d{4})-(\d{8})$', phone) print(result.group()) # 020-68886888 print(result.group(1)) # 020 print(result.group(2)) # 68886888