5. Why regex?
특정한 규칙을 가진 문자열의 집합을 표현하는 데 사용하는 식
문자열의 검색이나 치환에 편리하다.
100312467“WhySoLonely”“wondergirls”3014725201603062016-03-20T12:00:35+09:00
->“WhySoLonely”“wondergirls”2016-03-20T12:00
20. match vs search
import re
sample = '2016pycon'
re.match('[a-z]+', sample)
>>> None
re.search('[a-z]+', sample)
>>> <_sre.SRE_Match object; span=(4, 8), match='pycon'>
21. re module
re.search(pattern, string, flags=0)
= match되는 첫번째 문자열을 찾아줌
re.match(pattern, string, flags=0)
= string 처음부터 match되는지 확인
re.findall(pattern, string, flags=0)
= string 전체에서 pattern과 일치하는 것을 모두 찾아 list로
돌려 줌
22. Character classes
. 줄바꿈 문자를 제외한 모든 문자와 매치됨
d 모든 숫자와 매치됨 [0-9]
D 숫자가 아닌 문자와 매치됨 [^0-9]
w 숫자 또는 문자와 매치됨 [a-zA-Z0-9]
(파이썬에선 숫자도 포함)
W 숫자 또는 문자가 아닌 것과 매치됨 [^a-zA-Z0-9]
s 화이트 스페이스 문자와 매치됨
S 화이트 스페이스가 아닌 것과 매치됨
23. Anchors and Repetition
^abc$ 문자열의 시작/ 문자열의 마지막과 매치됨
* 0회 이상 반복
+ 1회 이상 반복
? 0회 또는 1회
{x} x회 반복 (e.g {3} )
{x,y} x회부터 y회까지 반복
[abc] 문자 집합 중 한 문자를 의미
[^abc] a,b,c 가 아닌 문자
[a-d] a, b, c or d 사이에 있는 문자를 의미
28. link: https://bugzilla.mozilla.org/show_bug.cgi?
id=1173199#c31
title: “Our primary goal is to un-fork the Tor Browser”
link: http://siliconangle.com/blog/2016/08/05/watson-
correctly-diagnoses-woman-after-doctors-were-stumped/
title: IBM Watson correctly diagnoses a form of leukemia
link: http://gping.io
title: Show HN: Gping.io – Like TinyURL for your car
link: http://bit-player.org/2016/the-39th-root-of-92
title: The 39th Root of 92
link: http://www.sciencealert.com/we-just-got-even-
weirder-results-about-the-alien-megastructure-star
title: Tabby's star is dimming at an incredible rate
우리가 원하는 Output
34. 그 외 유용한 것들
Vim: Find and Replace
:%s/old/new/g
http://vimregex.com/
1033303 -> 1233303, 1033213 -> 1233213
:%s/103(d{4})/1231/g
35.
36. str.find vs re.match vs in
http://stackoverflow.com/questions/4901523/whats-a-faster-operation-re-match-search-or-str-find
37. str.find vs re.match vs in
http://stackoverflow.com/questions/4901523/whats-a-faster-operation-re-match-search-or-str-find
strfind : 0.441393852234
re.match: 2.12302494049
in : 0.251421928406