[Python]Regular Expression Syntax

来源:互联网 发布:sql基础教程光盘 编辑:程序博客网 时间:2024/05/15 23:50
Element Meaning . Matches any character except /n(if DOTALL, also matches /n) ^ Matches start of string(if MULTILINE, also matches after /n) $ Matches end of string(if MULTILINE, also matches before /n) * Matches zero or more cases of the previous RE; greedy(match as many as possible) + Matches one or more cases of the previous RE; greedy(match as many as possible) ? Matches zero or one case of the previous RE; greedy(match one if possible) *?, +?, ?? Nongreedy versions of *, + and ?(match as few as possible) {m,n} Matches m to n cases of the previous RE(greedy) {m,n}? Matches m to n cases of the previous RE(nongreedy) [...] Matches any one of a set of characters contained within the brackets | Matches either preceding expression or following expression (...) Matches the RE within the parentheses and indicates a group (?iLmsux)   Alternate way to set optional flags; no errect on match (?:...)  Like (...), but does not indicate a group  (?P<id>...)  Like (...), but the group also gets the name id  (?P=id)  Matches whatever was previously matched by group named id  (?#...)  Content of parentheses is just a comment; no effect on match  (?=...)  Lookahead assertion: matches if RE ... matches what comes next, but does not consume any part of the string  (?!...)  Negative lookahead assertion: matches if RE ... does not match waht comes next, and does not consume any part of the string  (?<=...)  Lookbehind assertion: matches if there is a match ending at the current position for RE ... (... must match a fixed length)  (?<!...)  Negative lookbehind assertion: matches if there is no match ending at the current position for RE ... (... must match a fixed length) /number  Matches whatever was previously matched by group numbered number(groups are automatically numbered from 1 to 99) /A

Matches an empty string, but only at the start of the whole string

/b  Matches an empty string but only at the start or end of a word(a maximal sequence of alphanumeric characters; see also /w) /B  Matches an empty string, but not at the start or end of a word  /d  Matches one digit, like the set [0-9]  /D  Matches one non digit, like the set [^0-9] /s  Matches a whitespace character, like the set [/t/n/r/f/v]  /S  Matches a non whitespace character, like the set [^/t/n/r/f/v]  /w  Matches one alphanumeric character; unless LOCALE or UNICODE is set, /w is like [a-zA-Z0-9_]  /W  Matches one non alphanumeric character, the reverse of /w /Z  Matches an empty string, but only at the end of the whole string  //  Matches one backslash character   
原创粉丝点击