Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import re
# \d - matches any digit
# \D - matches any nondigit
sentence = '''I tried to call 123-4567 but I accidently
called 765_4321; when the person picked up, they said it
was 1-800-765-1111! How that works, I can't recall!'''
pattern = re.compile(r'\d\d\d-\d\d\d\d')
for match in re.finditer(pattern, sentence):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment