Disclaimer: If you need to reprint, you need to review the article below, in addition, please indicate the source link https://blog.csdn.net/qq_39714960/article/details/84318546 your article
Website:
- Blue shaded to match the text, syntax parsing, highly recommended
- Your regular expression is expressed as a graphics state machine
Learning Website
- Easy to learn regular expressions (geeks College reproduced in other people's) (see syntax available)
- Regular Expressions 30 minutes Start Tutorial
To learn righteousness
- Constant practice (which is the core around regular practice to learn the most effective)
- One must be thinking about how to achieve their own, rather than rationality would like to see the answer
- There is a demand can realize their regular engine
Exercise
Wait filled pit
grammar
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. Serial " \\ ," matching " \ " and " \( " the match ( " ." |
^ | Matches the beginning of the string. If the object is set RegExp Multiline property, ^ also matches " \n " or " \r position" after. |
$ | Matches the input end of the string. If the RegExp object's Multiline property is set, $ also matches " \n " or " \r position before." |
* | 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+ " can match " zo " and zoo " ", but can not match z " ." + Is equivalent to {1}. |
? | Matches the preceding subexpression zero or one. For example, " do(es)? " matches " does " or " does " in 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 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 o " ", but it can match " foooood all o" 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 first 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+? " will match a single o " " and " o+ " matches all the o " ." |
. | In addition to matching " \``n any single character other than" in. To match including " \``n " any characters, including use as " (.|\n) " model. |
(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 or character (|) " to a combination of the various parts of the model is useful. For example, " industr(?:y|ies) " it is more than a ' industry|industries ' more brief expressions. |
(?=pattern) | Forward definitely pre-investigation, matching the search string at the beginning of the string any pattern matching. 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) " matches " Windows2000 " in Windows " ", but not " Windows3.1 " the 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) | Forward negative 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) " matches " Windows3.1 " in Windows " ", but not " Windows2000 " 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 |
(?<=pattern) | Reverse certainly pre-investigation, and certainly pre-investigation Quasi forward, but in the opposite direction. For example, " (?<=95|98|NT|2000)Windows " matches " 2000Windows " in Windows " ", but not " 3.1Windows " the Windows " ." |
(?<!pattern) | Reverse negative pre-check, with a negative pre-investigation Quasi forward, but in the opposite direction. For example " (?<!95|98|NT|2000)Windows " matches " 3.1Windows " in Windows " ", but not " 2000Windows " the Windows " ." |
x | and | Match x or y. For example, " z|food " matches " 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 a " ." |
[^xyz] | Negative character sets. Matches any character not included. For example, " [^abc] " matches " plain " in p " ." |
[a-z] | Range of characters. Matches any character within the specified range. For example, " [a-z] " matches " a " to " z " any lowercase characters in the range. |
[^a-z] | Negative character range. Matches any character not in any specified range. For example, " [^a-z] " may not match any " a " to " z " Any range. |
\b | Matches a word boundary, that is, it refers to the location and spaces between words. For example, " er\b " matches " never " in er " ", but not " verb " the er " ." |
\B | 匹配非单词边界。“er\B ”能匹配“verb ”中的“er ”,但不能匹配“never ”中的“er ”。 |
\cx | 匹配由x指明的控制字符。例如,\cM匹配一个Control-M或回车符。x的值必须为A-Z或a-z之一。否则,将c视为一个原义的“c ”字符。 |
\d | 匹配一个数字字符。等价于[0-9]。 |
\D | 匹配一个非数字字符。等价于[^0-9]。 |
\f | 匹配一个换页符。等价于\x0c和\cL。 |
\n | 匹配一个换行符。等价于\x0a和\cJ。 |
\r | 匹配一个回车符。等价于\x0d和\cM。 |
\s | 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。 |
\S | 匹配任何非空白字符。等价于[^ \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匹配版权符号(©)。 |