ure1.py 667 Bytes
Newer Older
Paul Sokolovsky's avatar
Paul Sokolovsky committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
try:
    import ure as re
except ImportError:
    import re

r = re.compile(".+")
m = r.match("abc")
print(m.group(0))
try:
    m.group(1)
except IndexError:
    print("IndexError")

r = re.compile("(.+)1")
m = r.match("xyz781")
print(m.group(0))
print(m.group(1))
try:
    m.group(2)
except IndexError:
    print("IndexError")

23
24
25
26
27
28
29
r = re.compile("[a-c]")
m = r.match("a")
print(m.group(0))
m = r.match("d")
print(m)
m = r.match("A")
print(m)
Paul Sokolovsky's avatar
Paul Sokolovsky committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

r = re.compile("o+")
m = r.search("foobar")
print(m.group(0))
try:
    m.group(1)
except IndexError:
    print("IndexError")


m = re.match(".*", "foo")
print(m.group(0))

m = re.search("w.r", "hello world")
print(m.group(0))