(Turn) All symbols of regular expressions are explained

 Reprinted from: http://www.cnblogs.com/yirlin/archive/2006/04/12/373222.html

 

character description
\ Marks the next character as a special character, or a literal character, or a backreference, or an octal escape. For example, 'n' matches the character "n". '\n' matches a newline. The sequence '\\' matches "\" and "\(" matches "(".
^ Matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after '\n' or '\r'.
$ Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches the position before '\n' or '\r'.
* Matches the preceding subexpression zero or more times. For example, zo* matches "z" as well as "zoo". * is equivalent to {0,}.
+ Matches the preceding subexpression one or more times. For example, 'zo+' matches "zo" and "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "do(es)?" matches "do" or "do" in "does". ? Equivalent to {0,1}.
{n} n is a non-negative integer. Matches a certain number of n times. For example, 'o{2}' would not match the 'o' in "Bob", but would match the two o's in "food".
{n,} n is a non-negative integer. Match at least n times. For example, 'o{2,}' would not match the 'o' in "Bob", but would match all o's in "foooood". 'o{1,}' is equivalent to 'o+'. 'o{0,}' is equivalent to 'o*'.
{n,m} Both m and n are non-negative integers, where n <= m. Matches at least n times and at most m times. For example, "o{1,3}" will match the first three o's in "fooooood". 'o{0,1}' is equivalent to 'o?'. Note that there can be no spaces between the comma and the two numbers.
? When the character immediately follows any one of the other qualifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. The non-greedy mode matches as little of the searched string as possible, while the default greedy mode matches as much of the searched string as possible. For example, for the string "oooo", 'o+?' would match a single "o", and 'o+' would match all 'o's.
. Matches any single character except "\n". To match any character including '\n', use a pattern like '[.\n]'.
(pattern) Match pattern and get that match. The retrieved matches can be obtained from the resulting Matches collection, using the SubMatches collection in VBScript and the $0…$9 properties in JScript. To match parentheses characters, use '\(' or '\)'.
(?:pattern) Matches pattern but does not fetch the result of the match, which means that this is a non-fetching match and is not stored for later use. This is useful when using the "or" character (|) to combine parts of a pattern. For example, 'industr(?:y|ies) is a shorter expression than 'industry|industries'.
(?=pattern) Forward lookahead, matches the lookup string at the beginning of any string matching pattern. This is a non-acquisition match, that is, the match does not need to be acquired for later use. For example, 'Windows (?=95|98|NT|2000)' matches "Windows" in "Windows 2000", but not "Windows" in "Windows 3.1". Lookahead consumes no characters, that is, after a match occurs, the search for the next match begins immediately after the last match, not after the character containing the lookahead.
(?!pattern) Negative lookahead, matches the lookup string at the beginning of any string that does not match pattern. This is a non-acquisition match, that is, the match does not need to be acquired for later use. For example 'Windows (?!95|98|NT|2000)' matches "Windows" in "Windows 3.1", but not "Windows" in "Windows 2000". Lookahead consumes no characters, that is, after a match occurs, the search for the next match begins immediately after the last match, not after the character containing the lookahead
x|y Match x or y. For example, 'z|food' matches "z" or "food". '(z|f)ood' matches "zood" or "food".
[xyz] character collection. Matches any one of the included characters. For example, '[abc]' can match 'a' in "plain".
[^xyz] A collection of negative characters. Matches any character not included. For example, '[^abc]' matches the 'p' in "plain".
[a-z] character range. Matches any character in the specified range. For example, '[az]' matches any lowercase alphabetic character in the range 'a' to 'z'.
[^a-z] Negative character range. Matches any arbitrary character not in the specified range. For example, '[^az]' matches any character not in the range 'a' to 'z'.
\b Matches a word boundary, that is, the position between a word and a space. For example, 'er\b' can match the 'er' in "never", but not the 'er' in "verb".
\B Match non-word boundaries. 'er\B' matches the 'er' in "verb", but not the 'er' in "never".
\cx Matches the control character specified by x. For example, \cM matches a Control-M or carriage return. The value of x must be one of AZ or az. Otherwise, treat c as a literal 'c' character.
\d Match a numeric character. Equivalent to [0-9].
\D Matches a non-numeric character. Equivalent to [^0-9].
\f Matches a form feed character. Equivalent to \x0c and \cL.
\n Matches a newline character. Equivalent to \x0a and \cJ.
\r Matches a carriage return. Equivalent to \x0d and \cM.
\s Matches any whitespace character, including spaces, tabs, form feeds, and more. Equivalent to [ \f\n\r\t\v].
\S matches any non-whitespace character. 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 http://10.200.1.11:23101/article/api/json?id=326685027&siteId=291194637