regex.py 369 B

12345678910111213
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import re
  4. print('Test: 010-12345')
  5. m = re.match(r'^(\d{3})-(\d{3,8})$', '010-12345')
  6. print(m.group(1), m.group(2))
  7. t = '19:05:30'
  8. print('Test:', t)
  9. m = re.match(r'^(0[0-9]|1[0-9]|2[0-3]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])$', t)
  10. print(m.groups())