fork download
  1. import re
  2.  
  3. phoneNumRegex = re.compile(r'(?<!\d)\d{3}\-\d{3}\-\d{4}(?!\d)')
  4.  
  5. mo1 = phoneNumRegex.search('My number is 415-555-42424854-201.')
  6. if mo1 is not None:
  7. print('Phone number found: ' + mo1.group())
  8. else:
  9. print("Pattern is not matched")
  10.  
  11. mo2 = phoneNumRegex.search('My number is 415-555-4242.')
  12. if mo2 is not None:
  13. print('Phone number found: ' + mo2.group())
  14. else:
  15. print("Pattern is not matched")
Success #stdin #stdout 0.02s 9616KB
stdin
Standard input is empty
stdout
Pattern is not matched
Phone number found: 415-555-4242