본문 바로가기
정규표현식

[ Python ] 정규표현식 Table 및 우선순위

by fiasco 2022. 11. 1.
 
Special characters 
\ escape special characters
. matches any character
^ matches beginning of string
$ matches end of string
[5b-d] matches any chars '5', 'b', 'c' or 'd'
[^a-c6] matches any char except 'a', 'b', 'c' or '6'
R|S matches either regex R or regex S
() creates a capture group and indicates precedence
Quantifiers 
* 0 or more (append ? for non-greedy)
+ 1 or more (append ? for non-greedy)
? 0 or 1 (append ? for non-greedy)
{m} exactly mm occurrences
{m, n} from m to n. m defaults to 0, n to infinity
{m, n}? from m to n, as few as possible
Special sequences 
\A start of string
\b matches empty string at word boundary (between \w and \W)
\B matches empty string not at word boundary
\d digit
\D non-digit
\s whitespace: [ \t\n\r\f\v]
\S non-whitespace
\w alphanumeric: [0-9a-zA-Z_]
\W non-alphanumeric
\Z end of string
\g<id> matches a previously defined group
Extensions
(?iLmsux) matches empty string, sets re.X flags
(?:...) non-capturing version of regular parentheses
(?P<name>...) creates a named capturing group
(?P=name) matches whatever matched previously named group
(?#...) a comment; ignored
(?=...) lookahead assertion: matches without consuming
(?!...) negative lookahead assertion
(?<=...) lookbehind assertion: matches if preceded
(?<!...) negative lookbehind assertion
(?(id)yes|no) match 'yes' if group 'id' matched, else 'no'
 

연산 우선순위

연산자 설명
\ Escape
(), (?:), (?=), [] 괄호와 대괄호
*, +, ?, {n}, {n,}, {n,m} 수량자
^, $, \메타문자, 문자 앵커와 시퀀스
| 교체
 

 

'정규표현식' 카테고리의 다른 글

[ python ] 정규표현식[5]  (0) 2022.10.31
[ python ] 정규표현식[4]  (0) 2022.10.30
[ Python ] 정규표현식[3]  (0) 2022.10.27
[ python ] 정규표현식[2]  (0) 2022.10.27
[ python ] 정규표현식[1]  (0) 2022.10.27