Reference
https://docs.python.org/3/library/re.html
https://wikidocs.net/4308#findall
import re
[ ] : 문자 클래스
- : 범위
. : 하나의 모든 문자; \n을 제외하나 re.DOTALL을 통해 \n도 포함 가능; [.]은 문자 .을 의미
? + * : 0~1회, 1~회, 0~회 반복
{m, n} : m~n회 반복
^ : not
\d : [0-9]
\D : [^0-9]
\w : [a-zA-Z0-9_]
\W : [^a-zA-Z0-9_]
re.search(sentence)
# return Match object or None
첫 문자부터 패턴을 만족시켜야 하는 것이 search와 다르다.
re.match(sentence)
# return Match object or None
search and match method is used in if statement:
Match objects always have a boolean value of True. Since match() and search() return None when there is no match, you can test whether there was a match with a simple if statement:
+ Match.group()은 object의 패턴을 출력
패턴을 만족하는 모든 문자열을 패턴별로 나누어 리스트에 저장, 출력
re.findall(sentence)
# return list