-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_regexp.py
67 lines (52 loc) · 851 Bytes
/
my_regexp.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import re
# find one boolean
if re.match('a(.*?)c', 'abc'):
print('found')
else:
print('not found')
if re.match('a(.*?)c', 'ab1'):
print('found')
else:
print('not found')
print()
# found
# not found
# find one
x = re.search('a(.*?)c', 'abc')
print(x.group(1))
print()
# b
# find all
x = re.finditer('a(.*?)c', 'abca1c', re.MULTILINE)
for q in x:
print(q.groups()[0])
print()
# b
# 1
# todo find multiline
x = re.finditer('''a(.*?)c''', '''ab
ca1
c''', re.MULTILINE)
for q in x:
print(q.groups()[0])
print()
# b
# 1
# replace all
print(re.sub("a", "b", "aaasdasdgaawergageaweg"))
print()
# bbbsdbsdgbbwergbgebweg
rx_sequence = re.compile('''1111111
<b>123
(.*?)
567</b>
1111111''', re.MULTILINE)
text = '''
1111111
<b>123
345
567</b>
1111111
'''
for match in rx_sequence.finditer(text):
print(match.groups())