Python Regular Expressions Example


SUBMITTED BY: Bun

DATE: Feb. 20, 2016, 2:36 p.m.

FORMAT: Python 3

SIZE: 207 Bytes

HITS: 1049

  1. import re
  2. for test_string in ['555-1212', 'ILL-EGAL']:
  3. if re.match(r'^\d{3}-\d{4}$', test_string):
  4. print test_string, 'is a valid phone number'
  5. else:
  6. print test_string, 'invalid'

comments powered by Disqus