python regular expression special characters

character description
\ The next character is marked as a special character, or a literal character, or a backward reference, or an octal escape. For example, 'n' matches the character "n". '\ N' matches a newline. Sequence '\\' matches "\" and "\ (" the match "(."
^ Matches the beginning of the string. If the object is set RegExp Multiline property, also matches ^ '\ n' position after or '\ r'.
$ Matches the input end of the string. If the object is set RegExp Multiline property, $ also matches the position before the '\ n' or '\ r'.
* Matches the preceding subexpression zero or more times. For example, zo * matches "z" and "zoo". * Is equivalent to {0}.
+ Matches the preceding subexpression one or more times. For example, 'zo +' will match "zo" and "zoo", but can not match the "z". + Is equivalent to {1}.
? Matches the preceding subexpression zero or one. For example, "do (es)?" Matches "do" or "does" in the "do". ? Is equivalent to {0,1}.
{n} n is a nonnegative integer. Matching the determined n times. For example, 'o {2}' does not match the "Bob" in the 'o', but can match the "food" in the two o.
{n,} n is a nonnegative integer. Matching at least n times. For example, 'o {2,}' does not match the "Bob" in the 'o', but it can match all o "foooood" in. 'O {1,}' is equivalent to 'o +'. 'O {0,}' is equivalent to 'o *'.
{n,m} m and n are non-negative integers, where n <= m. Match at least n times and match up to m times. For example, "o {1,3}" will match "fooooood" in the previous three o. 'O {0,1}' is equivalent to 'o?'. Please note that no spaces between the comma and the two numbers.
? When the character immediately to any other qualifier (*, +,?, {N}, {n,}, {n, m}) when the rear, non-greedy matching pattern. Non-greedy pattern matches as little as possible the search string, and the default greedy pattern matches as much of the string search. For example, the string "oooo", 'o +?' Matches a single "o", and 'o +' will match all 'o'.
. Matches any single character except "\ n" is. To match include '\ n', including any character, like the use of '[. \ N]' mode.
(pattern) Match the pattern and get the match. The matching can be obtained from the Matches have been used in collection SubMatches VBScript, JScript is used in the $ 0 ... $ 9 properties. To match parentheses characters, use '\ (' or '\)'.
(?:pattern) But not to acquire matching pattern matching results, that this is a non-access match, not stored for later use. This use of "or" character (|) to combine the various parts of a model is useful. For example, 'industr (:? Y | ies) is a ratio of' industry | more brief expressions industries'.
(?=pattern) Positive pre-investigation, matching the search string at the beginning of any match pattern string. This is a non-access match, that is, the match does not need to obtain for later use. For example, 'Windows (= 95 |? 98 | NT | 2000)' can match the "Windows 2000" in the "Windows", but can not match the "Windows 3.1" "Windows". Pre-check does not consume characters, that is, after a match occurs, the last match after the next match to start the search immediately, rather than starting from the characters that contains pre-investigation.
(?!pattern) Negative pre-investigation, at the beginning of any match pattern string matching search string. This is a non-access match, that is, the match does not need to obtain for later use. For example 'Windows (95 |?! 98 | NT | 2000)' can match the "Windows 3.1" "Windows", but can not match the "Windows 2000" in the "Windows". Pre-check does not consume characters, that is, after a match occurs, after the last match started immediately next match search, rather than starting from the characters that contains pre-investigation
x | and Match x or y. For example, 'z | food' can match the "z" or "food". '(Z | f) ood' the match "zood" or "food".
[xyz] Set of characters. Matches any character included. For example, '[abc]' matches "plain" in the 'a'.
[^xyz] Negative character sets. Matches any character not included. For example, '[^ abc]' matches "plain" the 'p'.
[a-z] Range of characters. Matches any character within the specified range. For example, '[az]' match 'a' to any lowercase alphabetic characters 'z' within range.
[^a-z] Negative character range. Matches any character not in any specified range. For example, '[^ az]' can not match any 'a' to an arbitrary character 'z' within range.
\b Matches a word boundary, that is, it refers to the location and spaces between words. For example, 'er \ b' matches "never" in the 'er', but does not match the "verb" in the 'er'.
\B Matching non-word boundary. 'Er \ B' matches "verb" in the 'er', but does not match the "never" in the 'er'.
\cx Match control characters specified by the x. For example, \ cM matches a Control-M or carriage return. The value of x must be AZ or az. Otherwise, c as a literal 'c' character.
\d Matches a digit character. Equivalent to [0-9].
\D Matching a non-numeric characters. It is equivalent to [^ 0-9].
\f Match a feed character. Equivalent to \ x0c and \ cL.
\n Matches a newline. Equivalent to \ x0a and \ cJ.
\r Matching a carriage return. Equivalent to \ x0d and \ cM.
\s Matches any whitespace characters, including spaces, tabs, page breaks, and so on. Is equivalent to [\ f \ n \ r \ t \ v].
\S Matches any non-whitespace characters. Is equivalent to [^ \ f \ n \ r \ t \ v].
\t 匹配一个制表符。等价于 \x09 和 \cI。
\v 匹配一个垂直制表符。等价于 \x0b 和 \cK。
\w 匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。
\W 匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。
\xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如,'\x41' 匹配 "A"。'\x041' 则等价于 '\x04' & "1"。正则表达式中可以使用 ASCII 编码。.
\num 匹配 num,其中 num 是一个正整数。对所获取的匹配的引用。例如,'(.)\1' 匹配两个连续的相同字符。
\n 标识一个八进制转义值或一个向后引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为向后引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
\nm 标识一个八进制转义值或一个向后引用。如果 \nm 之前至少有 nm 个获得子表达式,则 nm 为向后引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的向后引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。
\nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
\un 匹配 n,其中 n 是一个用四个十六进制数字表示的 Unicode 字符。例如, \u00A9 匹配版权符号 (?)。

Guess you like

Origin www.cnblogs.com/paulversion/p/11565893.html