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')
Last Updated on 2024-05-30 by gantovnik
Recent Comments