2014-09-14 23:14:28 +01:00
|
|
|
try:
|
2022-08-18 07:57:45 +01:00
|
|
|
import re
|
2014-09-14 23:14:28 +01:00
|
|
|
except ImportError:
|
2022-08-18 07:57:45 +01:00
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
2014-09-14 23:14:28 +01:00
|
|
|
|
|
|
|
r = re.compile(" ")
|
|
|
|
s = r.split("a b c foobar")
|
|
|
|
print(s)
|
|
|
|
|
|
|
|
r = re.compile(" +")
|
|
|
|
s = r.split("a b c foobar")
|
|
|
|
print(s)
|
|
|
|
|
|
|
|
r = re.compile(" +")
|
|
|
|
s = r.split("a b c foobar", 1)
|
|
|
|
print(s)
|
|
|
|
|
|
|
|
r = re.compile(" +")
|
|
|
|
s = r.split("a b c foobar", 2)
|
|
|
|
print(s)
|
|
|
|
|
|
|
|
r = re.compile("[a-f]+")
|
|
|
|
s = r.split("0a3b9")
|
2015-02-21 10:39:41 +00:00
|
|
|
print(s)
|
2017-06-30 23:25:23 +01:00
|
|
|
|
|
|
|
# bytes objects
|
|
|
|
r = re.compile(b"x")
|
|
|
|
s = r.split(b"fooxbar")
|
|
|
|
print(s)
|
2022-03-10 00:51:42 +00:00
|
|
|
|
|
|
|
# using ^
|
|
|
|
r = re.compile("^ab")
|
|
|
|
s = r.split("abababcabab")
|
|
|
|
print(s)
|
|
|
|
|
|
|
|
# using ^ with |
|
|
|
|
r = re.compile("^ab|cab")
|
|
|
|
s = r.split("abababcabab")
|
|
|
|
print(s)
|