import re phoneNumRegex = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)') mo = phoneNumRegex.search('Phone number: 415-555-4242') print(mo.group(1)) print(mo.group(2)) print(mo.group(0)) print(mo.groups())
Output:
415 555-4242 415-555-4242 ('415', '555-4242')
Recent Comments