diff options
Diffstat (limited to 'tests/extmod/re_namedclass.py')
| -rw-r--r-- | tests/extmod/re_namedclass.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/extmod/re_namedclass.py b/tests/extmod/re_namedclass.py new file mode 100644 index 000000000..442172f4a --- /dev/null +++ b/tests/extmod/re_namedclass.py @@ -0,0 +1,36 @@ +# test named char classes + +try: + import re +except ImportError: + print("SKIP") + raise SystemExit + + +def print_groups(match): + print("----") + try: + i = 0 + while True: + print(match.group(i)) + i += 1 + except IndexError: + pass + + +m = re.match(r"\w+", "1234hello567 abc") +print_groups(m) + +m = re.match(r"(\w+)\s+(\w+)", "ABC \t1234hello567 abc") +print_groups(m) + +m = re.match(r"(\S+)\s+(\D+)", "ABC \thello abc567 abc") +print_groups(m) + +m = re.match(r"(([0-9]*)([a-z]*)\d*)", "1234hello567") +print_groups(m) + +# named class within a class set +print_groups(re.match("([^\s]+)\s*([^\s]+)", "1 23")) +print_groups(re.match("([\s\d]+)([\W]+)", "1 2-+=")) +print_groups(re.match("([\W]+)([^\W]+)([^\S]+)([^\D]+)", " a_1 23")) |
