forked from ElvinKim/2018_1_ITA_python_class_C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20180131_1.py
70 lines (50 loc) · 1.34 KB
/
20180131_1.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
67
68
69
70
"""
정규 표현식
"""
import re
print("{:-^20}".format(" match "))
pattern = re.compile("[a-z]+")
sample_str = "Pabc aaaa bbb Aabbb"
m = pattern.match(sample_str)
print(m)
print("{:-^20}".format(" search "))
pattern = re.compile("[a-z]+")
sample_str = "Pabc aaaa bbb Aabbb"
m = pattern.search(sample_str)
print(m)
print("{:-^20}".format(" find all "))
pattern = re.compile("[a-z]+")
sample_str = "Pabc aaaa bbb Aabbb"
match_results_lst = pattern.findall(sample_str)
print(match_results_lst)
print("{:-^20}".format(" find iter "))
pattern = re.compile("[a-z]+")
sample_str = "Pabc aaaa bbb Aabbb"
match_results_iter = pattern.finditer(sample_str)
for m in match_results_iter:
print(m.span())
print("{:-^20}".format(" match obj "))
pattern = re.compile("[a-z]+")
sample_str = "Pabc aaaa bbb Aabbb"
m = pattern.search(sample_str)
print(m)
print(m.group())
print(m.start())
print(m.end())
print(m.span())
print("{:-^20}".format(" compile option "))
pattern = re.compile("abc.abc")
m = pattern.match("abc\nabc")
print(m)
pattern = re.compile("abc.abc", re.DOTALL)
m = pattern.match("abc\nabc")
print(m)
print("{:-^20}".format(" greedy vs non-greedy "))
html = """
<div>
<span>aaa</span>
<div>TEST</div>
</div>
"""
pattern = re.compile("<.*?>", re.DOTALL)
print(pattern.findall(html))