You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
610 B
41 lines
610 B
10 years ago
|
try:
|
||
2 years ago
|
import re
|
||
10 years ago
|
except ImportError:
|
||
2 years ago
|
print("SKIP")
|
||
|
raise SystemExit
|
||
10 years ago
|
|
||
|
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")
|
||
10 years ago
|
print(s)
|
||
7 years ago
|
|
||
|
# bytes objects
|
||
|
r = re.compile(b"x")
|
||
|
s = r.split(b"fooxbar")
|
||
|
print(s)
|
||
3 years ago
|
|
||
|
# using ^
|
||
|
r = re.compile("^ab")
|
||
|
s = r.split("abababcabab")
|
||
|
print(s)
|
||
|
|
||
|
# using ^ with |
|
||
|
r = re.compile("^ab|cab")
|
||
|
s = r.split("abababcabab")
|
||
|
print(s)
|