1# test match.span(), and nested spans 2 3try: 4 import ure as re 5except ImportError: 6 try: 7 import re 8 except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12try: 13 m = re.match(".", "a") 14 m.span 15except AttributeError: 16 print("SKIP") 17 raise SystemExit 18 19 20def print_spans(match): 21 print("----") 22 try: 23 i = 0 24 while True: 25 print(match.span(i), match.start(i), match.end(i)) 26 i += 1 27 except IndexError: 28 pass 29 30 31m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567") 32print_spans(m) 33 34m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567") 35print_spans(m) 36 37# optional span that matches 38print_spans(re.match(r"(a)?b(c)", "abc")) 39 40# optional span that doesn't match 41print_spans(re.match(r"(a)?b(c)", "bc")) 42