[Python] Regular Expressions (파이썬 정규표현식)
Regular Expression (정규표현식) 정의 : 문자열에 대한 표현을 메타 문자로 표기하는 것
Regular Expression 실행 : 실제 문자열을 정규표현식과 매칭여부 검증
import re
| ^ | Matches the beginning of a line |
| $ | Matches the end of the line |
| . | Matches any character |
| \s | Matches whitespace |
| \S | Matches any non-whitespace character |
| * | Repeats a character zero or more times 0회 이상 반복 |
| *? | Repeats a character zero or more times (non-greedy) |
| + | Repeats a character one or more times 1회 이상 반복 |
| +? | Repeats a character one or more times (non-greedy) 1회 이상 반복 (최소 일치) |
| [aeiou] | Matches a single character in the listed set |
| [^XYZ] | Matches a single character not in the listed set |
| [a-z0-9] | The set of characters can include a range |
| ( | Indicates where string extraction is to start |
| ) | Indicates where string extraction is to end ( ) 괄호 안의 내용을 그룹화, reference를 생성을 종료 |
match( ) |
문자열의 처음부터 정규식과 일치하는지 확인 |
search( ) |
정규식과 일치하는지 문자열 전체에서 검색 |
findall( ) |
정규식과 일치하는 모든 문자열(substring)을 리스트로 반환 |
finditer( ) |
정규식과 일치하는 모든 문자열(substring)을 iterator 객체로 반환 |
sub( ) |
정규식과 일치하면 변경 |
| split( ) | 정규식과 일치하면 split 하여 반환 |