circuitpython/tests/extmod/ure_groups.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
652 B
Python
Raw Normal View History

# test match.groups()
try:
import ure as re
except ImportError:
try:
import re
except ImportError:
print("SKIP")
raise SystemExit
try:
m = re.match(".", "a")
m.groups
except AttributeError:
2021-03-15 09:57:36 -04:00
print("SKIP")
raise SystemExit
2021-03-15 09:57:36 -04:00
m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567")
print(m.groups())
2021-03-15 09:57:36 -04:00
m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567")
print(m.groups())
# optional group that matches
2021-03-15 09:57:36 -04:00
print(re.match(r"(a)?b(c)", "abc").groups())
# optional group that doesn't match
2021-03-15 09:57:36 -04:00
print(re.match(r"(a)?b(c)", "bc").groups())
# only a single match
2021-03-15 09:57:36 -04:00
print(re.match(r"abc", "abc").groups())