micropython-lib/re-pcre/test_re.py

22 wiersze
538 B
Python
Czysty Zwykły widok Historia

2014-04-11 18:18:31 +00:00
import re
m = re.search(r"a+", "caaab")
assert m.group(0) == "aaa"
m = re.match(r"(?ms)foo.*\Z", "foo\nbar")
assert m.group(0) == "foo\nbar"
2014-04-11 18:18:31 +00:00
assert re.match(r"a+", "caaab") is None
m = re.match(r"a+", "aaaab")
assert m.group(0) == "aaaa"
assert re.sub("a", "z", "caaab") == "czzzb"
assert re.sub("a+", "z", "caaab") == "czb"
assert re.sub("a", lambda m: m.group(0) * 2, "caaab") == "caaaaaab"
m = re.match(r"(\d+)\.(\d+)", "24.1632")
assert m.groups() == ('24', '1632')
2014-05-09 20:07:29 +00:00
assert re.escape(r"1243*&[]_dsfAd") == r"1243\*\&\[\]_dsfAd"