fork download
  1. import re
  2. phoneNum = re.compile(r'''
  3. (?:\d{3}-| # area code without parentheses but with dash
  4. \(\d{3}\)\ ) # -or- area code with parentheses and no dash
  5. \d{3} # first 3 digits
  6. - # second dash
  7. \d{4} # last 4 digits''', re.VERBOSE)
  8. print(phoneNum.findall('(415) 123-2342 and 415-905-1234 are the numbers.'))
Success #stdin #stdout 0.01s 6832KB
stdin
Standard input is empty
stdout
['(415) 123-2342', '415-905-1234']