Regular Expression Cheat Sheet

Regular expression quick reference table, source network address: http://www.jb51.net/tools/regexsc.htm

Regular Expression Cheat Sheet
字符 描述 \ ^ $ * + ? {n} {n,} {n,m} ? . (pattern) (?:pattern) (?=pattern) (?!pattern) (?<=pattern) (?<!pattern) x|y [xyz] [^xyz] [a-z] [^a-z] \b \B \cx \d \D \f \n \r \s \S \t \v \w \W \xn \num \n \nm \nml \un
Marks the next character as a special character, or a literal character, or a backreference, or an octal escape. For example, " n"matches the characters" n". " \n" matches a newline character. Serial " \\"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" and " zoo". * 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)?" can match " does" or " does" in " do". ? is equivalent to {0,1}.
n is a non-negative integer. Match a certain number of n times. For example, " o{2}" does not match " Bob" in " o", but does match foodtwo o's in " ".
n is a non-negative integer. Match at least n times. For example, " o{2,}" does not match " Bob" in " o", but matches fooooodall o's in " ". " o{1,}" is equivalent to " o+". " o{0,}" is equivalent to " o*".
Both m and n are non-negative integers, where n<=m. Match at least n times and at most m times. For example, " o{1,3}" will match foooooodthe first three o's in " ". " 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+?" will match a single " o", while " o+" will match all " o".
Matches \nany single character except " ". To match \nany character including " ", use (.|\n)a pattern like " ".
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 parenthesis characters, use " \(" or " \)".
Matches the pattern but does not get the result of the match, which means that this is a non-getting 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 industry|industriesexpression than " ".
Positive positive 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)" can match " Windows2000" in " Windows", but not " Windows3.1" in " Windows". 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.
Forward negative lookahead, which 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)" can match " Windows3.1" in " Windows", but not " Windows2000" in " Windows". 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
Reverse positive pre-check is similar to positive positive pre-check, but in the opposite direction. For example, " (?<=95|98|NT|2000)Windows" can match " 2000Windows" in " Windows", but not " 3.1Windows" in " Windows".
The reverse negative pre-check is similar to the forward negative pre-check, but in the opposite direction. For example " (?<!95|98|NT|2000)Windows" can match " 3.1Windows" in " Windows", but not " 2000Windows" in " Windows".
matches x or y. For example, " z|food"can match" z" or " food". " (z|f)ood" matches either " zood" or " food".
character collection. Matches any one of the included characters. For example, " [abc]" can match " plain" in " a".
负值字符集合。匹配未包含的任意字符。例如,“[^abc]"可以匹配"plain"中的"p"。
字符范围。匹配指定范围内的任意字符。例如,“[a-z]"可以匹配"a"到"z"范围内的任意小写字母字符。
负值字符范围。匹配任何不在指定范围内的任意字符。例如,“[^a-z]"可以匹配任何不在"a"到"z"范围内的任意字符。
匹配一个单词边界,也就是指单词和空格间的位置。例如,“er\b"可以匹配"never"中的"er",但不能匹配"verb"中的"er"。
匹配非单词边界。“er\B"能匹配"verb"中的"er",但不能匹配"never"中的"er"。
匹配由x指明的控制字符。例如,\cM匹配一个Control-M或回车符。x的值必须为A-Z或a-z之一。否则,将c视为一个原义的“c"字符。
匹配一个数字字符。等价于[0-9]。
匹配一个非数字字符。等价于[^0-9]。
匹配一个换页符。等价于\x0c和\cL。
匹配一个换行符。等价于\x0a和\cJ。
匹配一个回车符。等价于\x0d和\cM。
匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。
匹配任何非空白字符。等价于[^ \f\n\r\t\v]。
匹配一个制表符。等价于\x09和\cI。
匹配一个垂直制表符。等价于\x0b和\cK。
匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]"。
匹配任何非单词字符。等价于“[^A-Za-z0-9_]"。
匹配n,其中n为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如,“\x41"匹配"A"。"\x041"则等价于"\x04&1"。正则表达式中可以使用ASCII编码。.
匹配num,其中num是一个正整数。对所获取的匹配的引用。例如,“(.)\1"匹配两个连续的相同字符。
标识一个八进制转义值或一个向后引用。如果\n之前至少n个获取的子表达式,则n为向后引用。否则,如果n为八进制数字(0-7),则n为一个八进制转义值。
标识一个八进制转义值或一个向后引用。如果\nm之前至少有nm个获得子表达式,则nm为向后引用。如果\nm之前至少有n个获取,则n为一个后跟文字m的向后引用。如果前面的条件都不满足,若n和m均为八进制数字(0-7),则\nm将匹配八进制转义值nm。
如果n为八进制数字(0-3),且m和l均为八进制数字(0-7),则匹配八进制转义值nml。
匹配n,其中n是一个用四个十六进制数字表示的Unicode字符。例如,\u00A9匹配版权符号(©)。

 

常用正则表达式
Username Password Password 2 Hexadecimal Value Email URL IP Address HTML Tag Delete Code \\ Comments Match Double Byte Characters (including Chinese Characters) Chinese Characters (Characters) Chinese Characters Range in Unicode Encoding Chinese and Full-width Punctuation (Characters ) Date (Year-Month-Day) Date (Month/Day/Year) Time (Hour:Minute, 24-hour format) Mainland China Landline Phone Number Mainland China Mobile Number Mainland China Postal Code Mainland China ID Number (15 digits or 18 digit) non-negative integer (positive integer or zero) positive integer negative integer integer decimal blank line QQ number does not contain abc words match leading and trailing blank characters Edit commonly
/^[a-z0-9_-]{3,16}$/
/^[a-z0-9_-]{6,18}$/
(?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[AZ])(?=.*[az])(?!.* \n).*$ (consisting of numbers/uppercase letters/lowercase letters/punctuation marks, all four must be present, more than 8 digits)
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/或\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ 或 [a-zA-z]+://[^\s]*
/((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ 或 ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)
/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/或<(.*)(.*)>.*<\/\1>|<(.*) \/>
(?<!http:|\S)//.*$
[^\x00-\xff]
[\u4e00-\u9fa5]
/^[\u2E80-\u9FFF]+$/
[\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee]
(\d{4}|\d{2})-((0?([1-9]))|(1[1|2]))-((0?[1-9])|([12]([1-9]))|(3[0|1]))
((0?[1-9]{1})|(1[1|2]))/(0?[1-9]|([12][1-9])|(3[0|1]))/(\d{4}|\d{2})
((1|0?)[0-9]|2[0-3]):([0-5][0-9])
(\d{4}-|\d{3}-)?(\d{8}|\d{7})
1\d{10}
[1-9]\d{5}
\d{15}(\d\d[0-9xX])?
\d+
[0-9]*[1-9][0-9]*
-[0-9]*[1-9][0-9]*
-?\d+
(-?\d+)(\.\d+)?
\n\s*\r 或者 \n\n(editplus) 或者 ^[\s\S ]*\n 
[1-9]\d{4,}
\b((?!abc)\w)+\b
^\s*|\s*$
以下是针对特殊中文的一些替换(editplus)
 
^[0-9].*\n 
 
^[^第].*\n 
 
^[习题].*\n
 
^[\s\S ]*\n 
^[0-9]*\. 
^[\s\S ]*\n 
<p[^<>*]>
href="javascript:if\(confirm\('(.*?)'\)\)window\.location='(.*?)'"
<span style=".[^"]*rgb\(255,255,255\)">.[^<>]*</span>

<DIV class=xs0>[\s\S]*?</DIV>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326286352&siteId=291194637