ure_sub_unmatched.py 419 B

12345678910111213141516171819
  1. # test re.sub with unmatched groups, behaviour changed in CPython 3.5
  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. try:
  11. re.sub
  12. except AttributeError:
  13. print('SKIP')
  14. raise SystemExit
  15. # first group matches, second optional group doesn't so is replaced with a blank
  16. print(re.sub(r'(a)(b)?', r'\2-\1', '1a2'))