-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_re.py
More file actions
49 lines (30 loc) · 847 Bytes
/
Copy pathtest_re.py
File metadata and controls
49 lines (30 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
mm = re.search('\Aab', 'abs')
print mm.group(0)
mm = re.search('ab\Z', 'sab')
print mm.group(0)
# mm = re.search(r'\bcsd', '1csd')
# print mm.group(0)
mm = re.search(r'a\Bcsd', 'acsd')
print mm.group(0)
mm = re.search('(ab)', 'absabsab')
print mm.group()
mm = re.match('(ab)', 'absabsab')
print mm.groups()
mm = re.findall('(ab)', 'absabsab')
print mm
mm = re.search(r'\d(?<=\d)a', 'a3av')
print mm.group(0)
p = re.compile(r'\d+')
for m in p.finditer('one1two2three3four4'):
print m.group(),
print '\n'
p = re.compile(r'(\w+) (\w+)')
s = 'i say, hello world'
print p.sub(r'\2 \1', s)
print p.subn(r'\2 \1', s)
m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
print m.groupdict()
# mm = re.search('(?P<id>ab)', 'absabsab')
# mm = re.search((?p<name>'ab'), 'absabsab')
# print mm.group(0)