ure_namedclass.py 617 B

1234567891011121314151617181920212223242526272829303132
  1. # test named char classes
  2. try:
  3. import ure as re
  4. except ImportError:
  5. try:
  6. import re
  7. except ImportError:
  8. print("SKIP")
  9. raise SystemExit
  10. def print_groups(match):
  11. print('----')
  12. try:
  13. i = 0
  14. while True:
  15. print(m.group(i))
  16. i += 1
  17. except IndexError:
  18. pass
  19. m = re.match(r'\w+','1234hello567 abc')
  20. print_groups(m)
  21. m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc')
  22. print_groups(m)
  23. m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc')
  24. print_groups(m)
  25. m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567')
  26. print_groups(m)