The technical content is not high, mainly because regular expressions are often used, and debugging on the code is too troublesome. It is faster to do this ~~~ Send it to friends who like regular expressions ~~~
I am dizzy and can't find several regular examples to learn from new users. So now I have only three examples in my help file!
Because my language is not very easy to express, and it is difficult to make materials by myself, I hope some enthusiastic people will provide classic Regular Expression examples. It is best to attach a detailed explanation to help beginners learn!
<Br/> <style type = "text/css"> <! -- BODY {background: # 44B6FA url(1.jpg); BORDER-RIGHT: #000000 0px outset; FONT-SIZE: 9pt; LINE-HEIGHT: 14px; TEXT-DECORATION: none; margin-left: 6px; margin-top: 6px; margin-right: 6px; margin-bottom: 6px; border: 1 #000000 solid} td {FONT-SIZE: 10pt; color: blue; height: 30px; LINE-HEIGHT: 18px ;}. bu {BACKGROUND-COLOR: # f7f7f7; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: # ffffff 1px solid; BORD ER-RIGHT: #999999 1px solid; BORDER-TOP: # ffffff 1px solid; COLOR: #000000; FONT-SIZE: 9pt; HEIGHT: 20px; WIDTH: 60px }. tx1 {font-size: 12px; border: 1px solid; border-color: black #000000; color: # 0000FF} --> </style> <p> <br/> <center> <input type = "button" value = "regular example" onclick = "document. getElementById ('window2 '). style. display = 'none'; document. getElementById ('window3 '). style. display = 'inline'; "class = "Bu" style = "width: 200px;"> </center> </p> <p> a regular expression is a regular character (for example, a to z) and a text format consisting of special characters (called <I> metacharacters </I>. This mode describes one or more strings to be matched when searching the text subject. A regular expression is used as a template to match a character pattern with the searched string. </P> <p> here are some examples of regular expressions that may be encountered: </p> <table border = "1" cellspacing = "0" cols = "3" frame = "box" rules = "all"> <tr valign = "top"> <th width = "30%"> JScript </th> <th width = "30%"> VBScript </th> <th width = "40%"> match </th> </tr> <tr valign = "top"> <td width = "30%">/^ \ [\ t] * $/</td> <td width = "30%"> "^ \ [\ t] * $" </td> <td width = "40%"> matches a blank row. </Td> </tr> <tr valign = "top"> <td width = "30%">/\ d {2}-\ d {5}/</td> <td width = "30%"> "\ d {2}-\ d {5}" </td> <td width = "40%"> verify whether an ID number is composed A two-digit number, A hyphen and a five-digit combination. </Td> </tr> <tr valign = "top"> <td width = "30%">/<(. *)>. * <\/\ 1>/</td> <td width = "30%"> "<(. *)>. * <\/\ 1> "</td> <td width =" 40% "> matches an HTML Tag. </Td> </tr> </table> <p> The following table lists the metacharacters and their behaviors in the context of the regular expression: </p> <table border = "1" cellspacing = "0" cols = "2" frame = "box" rules = "all"> <tr valign = "top"> <th width = "16%"> character </th> <th width = "84%"> description </th> </tr> <tr valign = "top"> <td width = "16%" >\</td> <td width = "84%"> mark the next character as a special character, or a literal character, or a back reference, or an octal escape character. For example, 'n' matches the character "n ". '\ N' matches a line break. The sequence '\' matches "\" and "\ (" matches "(". </Td> </tr> <tr valign = "top"> <td width = "16%"> ^ </td> <td width = "84%"> match the input string. If the <B> RegExp </B> attribute of the <B> Multiline </B> object is set, ^ matches the position after '\ n' or' \ R. </Td> </tr> <tr valign = "top"> <td width = "16%" >$ </td> <td width = "84%"> match the input string. If the <B> RegExp </B> attribute of the <B> Multiline </B> object is set, $ also matches the position before '\ n' or' \ R. </Td> </tr> <tr valign = "top"> <td width = "16%"> * </td> <td width = "84%"> match the previous the subexpression is zero or multiple times. For example, zo * can match "z" and "zoo ". * Is equivalent to {0 ,}. </Td> </tr> <tr valign = "top"> <td width = "16%"> + </td> <td width = "84%"> match the previous a subexpression can be expressed once or multiple times. For example, 'Zo + 'can match "zo" and "zoo", but cannot match "z ". + Is equivalent to {1 ,}. </Td> </tr> <tr valign = "top"> <td width = "16%">? </Td> <td width = "84%"> match the previous subexpression zero or one time. For example, "do (es )? "Can match" do "in" do "or" does ".? It is equivalent to {0, 1 }. </Td> </tr> <tr valign = "top"> <td width = "16%" >{< I> n </I >}</td> <td width = "84%"> <I> n </I> is a non-negative integer. Match the specified <I> n </I> times. For example, 'O {2} 'cannot match 'O' in "Bob", but can match two o in "food. </Td> </tr> <tr valign = "top"> <td width = "16%" >{< I> n </I> ,} </td> <td width = "84%"> <I> n </I> is a non-negative integer. Match at least <I> n </I> times. For example, 'O {2,} 'cannot match 'O' in "Bob", but can match all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'. </Td> </tr> <tr valign = "top"> <td width = "16%" >{< I> n </I>, <I> m </I >}</td> <td width = "84%"> <I> m </I> and <I> n </I> are both non-negative integer, <I> n </I> <= <I> m </I>. Minimum <I> n </I> times and maximum <I> m </I> times. Liu, "o {1, 3}" will match the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note that there must be no space between a comma and two numbers. </Td> </tr> <tr valign = "top"> <td width = "16%">? </Td> <td width = "84%"> when the character follows any other delimiter (*, + ,?, {<I> n </I >},{ <I> n </I> ,},{ <I> n </I>, <I> m </I>}), the matching mode is not greedy. The non-Greedy mode matches as few searched strings as possible, while the default greedy mode matches as many searched strings as possible. For example, for strings "oooo", 'O ++? 'Will match a single "o", and 'O +' will match all 'O '. </Td> </tr> <tr valign = "top"> <td width = "16%">. </td> <td width = "84%"> match any single character except "\ n. To match any character including '\ n', use a pattern like' [. \ n. </Td> </tr> <tr valign = "top"> <td width = "16%"> (<I> pattern </I>) </td> <td width = "84%"> match <I> pattern </I> and obtain this match. The obtained match can be obtained from the generated Matches set. In VBScript, use the <B> SubMatches </B> set, and in JScript, use <B> $0 </B>... <B> $9 </B> attribute. To match the parentheses, use '\ (' or '\)'. </Td> </tr> <tr valign = "top"> <td width = "16%"> (?: <I> pattern </I>) </td> <td width = "84%"> match <I> pattern </I>, but the matching result is not obtained, that is to say, this is a non-acquisition match and will not be stored for future use. This is useful when you use the "or" character (|) to combine each part of a pattern. For example, 'industr (?: Y | ies) is a simpler expression than 'industry | industries. </Td> </tr> <tr valign = "top"> <td width = "16%"> (? = <I> pattern </I>) </td> <td width = "84%"> forward pre-query, search for a string at the beginning of any string that matches <I> pattern </I>. This is a non-get match, that is, the match does not need to be obtained for future use. For example, 'windows (? = 95 | 98 | NT | 2000) 'can match "Windows" in "Windows 2000", but cannot match "Windows" in "Windows 3.1 ". Pre-query does not consume characters, that is, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters. </Td> </tr> <tr valign = "top"> <td width = "16%"> (?! <I> pattern </I>) </td> <td width = "84%"> negative pre-query, match the search string at the beginning of any string that does not match Negative lookahead matches the search string at any point where a string not matching <I> pattern </I>. This is a non-get match, that is, the match does not need to be obtained for future use. For example, 'windows (?! 95 | 98 | NT | 2000) 'can match "Windows" in "Windows 3.1", but cannot match "Windows" in "Windows 2000 ". Pre-query does not consume characters, that is, after a match occurs, the next matching search starts immediately after the last match, instead of starting from </td> </tr> <tr valign = "top"> <td width = "16%"> <I> x </I >|< I> y </I> </td> <td width = "84%"> match <I> x </I> or <I> y </I>. For example, 'z | food' can match "z" or "food ". '(Z | f) ood' matches "zood" or "food ". </Td> </tr> <tr valign = "top"> <td width = "16%"> [<I> xyz </I>] </td> <td width = "84%"> Character Set combination. Match any character in it. For example, '[abc]' can match 'A' in "plain '. </Td> </tr> <tr valign = "top"> <td width = "16%"> [^ <I> xyz </I>] </td> <td width = "84%"> negative value character set combination. Match any character not included. For example, '[^ abc]' can match 'p' in "plain '. </Td> </tr> <tr valign = "top"> <td width = "16%"> [<I> a-z </I>] </td> <td width = "84%"> character range. Matches any character in the specified range. For example, '[a-z]' can match any lowercase letter in the range of 'A' to 'Z. </Td> </tr> <tr valign = "top"> <td width = "16%"> [^ <I> a-z </I>] </td> <td width = "84%"> negative character range. Matches any character that is not within the specified range. For example, '[^ a-z]' can match any character that is not in the range of 'A' to 'Z. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ B </td> <td width = "84%"> match word boundary, that is, the position between a word and a space. For example, 'er \ B 'can match 'er' in "never", but cannot match 'er 'in "verb '. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ B </td> <td width = "84%"> matched non-word boundary. 'Er \ B 'can match 'er' in "verb", but cannot match 'er 'in "never '. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ c <I> x </I> </td> <td width = "84%"> match the control characters specified by <I> x </I>. For example, \ cM matches a Control-M or carriage return character. The value of <I> x </I> must be either a A-Z or a-z. Otherwise, c is treated as an original 'C' character. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ d </td> <td width = "84%"> match number character. It is equivalent to [0-9]. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ D </td> <td width = "84%"> match non-numeric characters. It is equivalent to [^ 0-9]. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ f </td> <td width = "84%"> matches page Break. It is equivalent to \ x0c and \ cL. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ n </td> <td width = "84%"> match line Break. It is equivalent to \ x0a and \ cJ. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ r </td> <td width = "84%"> matches carriage return. It is equivalent to \ x0d and \ cM. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ s </td> <td width = "84%"> match any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v]. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ S </td> <td width = "84%"> match any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v]. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ t </td> <td width = "84%"> match tab. It is equivalent to \ x09 and \ cI. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ v </td> <td width = "84%"> match vertical tab. It is equivalent to \ x0b and \ cK. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ w </td> <td width = "84%"> matching includes any word character of an underscore. It is equivalent to '[A-Za-z0-9 _]'. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ W </td> <td width = "84%"> match any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ x <I> n </I> </td> <td width = "84%"> match <I> n </I>, <I> n </I> is the hexadecimal escape value. The hexadecimal escape value must be determined by the length of two numbers. For example, '\ x41' matches "". '\ X041' is equivalent to '\ x04' & "1 ". The regular expression can use ASCII encoding .. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ <I> num </I> </td> <td width = "84%"> match <I> num </I>, <I> num </I> is a positive integer. References to the obtained matching. For example, '(.) \ 1' matches two consecutive identical characters. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ <I> n </I> </td> <td width = "84%"> identifies an octal escape value or a back reference. If at least <I> n </I> subexpressions obtained before <I> n </I>, <I> n </I> is a backward reference. Otherwise, if <I> n </I> is an octal digit (0-7), <I> n </I> is an octal escape value. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ <I> nm </I> </td> <td width = "84%"> identifies an octal escape value or a back reference. If at least is preceded by at least <I> nm </I> exists before \ <I> nm </I>, <I> nm </I> is the backward reference. If at least <I> n </I> is obtained before <I> nm </I>, <I> n </I> is a back reference followed by <I> m </I>. If none of the preceding conditions are met, if both <I> n </I> and <I> m </I> are Octal numbers (0-7 ), then \ <I> nm </I> matches the octal escape value <I> nm </I>. </Td> </tr> <tr valign = "top"> <td width = "16%"> \ <I> nml </I> </td> <td width = "84%"> If <I> n </I> is an octal digit (0-3 ), if both <I> m </I> and <I> l </I> are Octal numbers (0-7), the octal escape value <I> nml is matched. </I> </td> </tr> <tr valign = "top"> <td width = "16%"> \ u <I> n </I> </ td> <td width = "84%"> match <I> n </I>, <I> n </I> is a Unicode character represented by four hexadecimal numbers. For example, \ u00A9 matches the copyright symbol (?). </Td> </tr> </table> <p> <br/> <center> <button class = "bu" style = "width: 300px; "onclick =" sender (); "> the following content is purely done by an individual. If there is any missing content, please correct it! </Button> <br/> <input type = "button" class = "bu" style = "width: 300px;" onclick = "document. getElementById ('window3 '). style. display = 'none'; document. getElementById ('window2 '). style. display = 'inline'; "value =" Regular Expression "> </center> </p> <p> Example 1 :. + </p> <p> explanation: This is the simplest line of all matching, that is, the obtained content is a whole line of content! Because ". "Is all character sets except the line feed (\ n), and" + "represents at least one character set, which together has at least one character set except the line feed, the line is separated by a line break (\ r \ n), so this regular expression represents a line, because the line break contains the \ r ". "The metacharacters own the characters, so even if the behavior is null, it will match. If it is changed to [^ \ r \ n] +, it will not match the blank line! <Input type = "button" value = "test" class = "bu" onclick = "set ('first line \ n third line ','. + '); "> <p> Example 2: <. +?> </P> <p> This matches the Regular Expression of HTML elements! In the regular expression? Non-Greedy mode. For more information, see regular expression instructions! That is, if the first matching match is met, the search will be stopped! If it is not added, it will be searched until the last>! <Input type = "button" value = "test" class = "bu" onclick = "set ('<font> test <\/font>', '<. +?> '); "> If no "? ", Search results in greedy mode: <input type = "button" value = "test" class = "bu" onclick = "set ('<font> test <\/font> other irrelevant content ', '<. +> '); "> </p> <p> Example 3: <tr. *?> [\ S \ S] *? <\/Tr> </p> <p> the regular expression matches the tr row in the table! And match across line breaks! First, </p> <tr> matches the start of tr. Because some tr start with a parameter, Add .*? Match the parameter. If no parameter exists, then .*? Empty! [\ S \ S] matches task characters, including line breaks, because \ s matches blank characters, and \ S is opposite to it, the combination of two character sets and "[]" represents all computer characters! "*" Indicates zero or infinite strings. All strings are matched together ,"? "Non-Greedy mode, that is, stop searching after finding the first one, example 2: <input type = "button" value = "test" class = "bu" onclick = "set ('<table> \ n <tr> \ n <td> related content \ n <\/td> \ n <\/tr> \ n <tr bgcolor = red> <td> related content <\/td> <\/ tr> <table> ', '<tr. *?> [\ S \ S] *? <\\/ Tr> '); "> <br/> <textarea style =" font-size: 13px; "name =" a "rows =" 20 "cols =" 120 "class =" tx1 "> </p> <p> regular expression: <input type = "text" size = "60" name = "zhe" class = "tx1"> <br/> <select onchange = "zhe. value + = this. value; this. selectedIndex = 0; "> <option> common characters </option> <option value = ". "> Any character except line breaks </option> <option value =" [] "> character in the range </option> <option value =" [^] "> </option> <option value = "? "> Non-Greedy mode </option> <option value =" * "> 0 or unlimited </option> <option value =" + "> at least one </option> <option value = "{n}"> contains n </option> <option value = "{n ,} "> contains at least n </option> <option value =" {n, m} "> contains n to m </option> <option value = "() "> obtain the sub-match </option> <option value = "(? :) "> Non-obtain sub-match </option> <option value = "(? =) "> Forward pre-query </option> <option value = "(?!) "> Negative pre-query </option> <option value =" [\ s \ S] "> Any character including line feed </option> <option value =" [a-z] "> lowercase letters </option> <option value =" [a-zA-Z] "> uppercase and lowercase letters </option> <option value =" [\ u4e00-\ u9fa5] "> Chinese </option> <option value =" [-~] "> Common characters (single byte) </option> </select> <p> replace: <input type = "text" size = "60" name = "ti" class = "tx1"> <br/> <select onchange = "if (this. selectedIndex! = 10) ti. value + = this. value; else ti. value = this. value; this. selectedIndex = 0; "> <option> common characters </option> <option value =" $1 "> sub-match 1 </option> <option value =" $2 "> sub-match 2 </option> <option value = "$3"> sub-Match 3 </option> <option value = "$4"> sub-match 4 </option> <option value =" $5 "> sub-match 5 </option> <option value =" $6 "> sub-match 6 </option> <option value =" $7 "> sub-match 7 </option> <option value = "$8"> sub-match 8 </option> <option value = "$9"> sub-match 9 </option> <option value =" func Tion (a) {return ;} "> function </option> </select> <p> <input type =" button "value =" Search "onclick =" if (zhe. value! = '') Zhen (0)" class = "bu"> <input type = "button" value = "replace" onclick = "if (zhe. value! = '') Zhen (1)" class = "bu"> <input type = "button" value = "generate" onclick = "if (zhe. value! = '') Shen ()" class = "bu"> <input type = "button" value = "g" name = "gg" onclick = "if (this. value = 'G') {this. value = '';} else {this. value = 'G';}; l = gg. value + ii. value + mm. value; "style =" width: 25 "class =" bu "> <input type =" button "value =" I "name =" ii "onclick =" if (this. value = 'I') {this. value = '';} else {this. value = 'I';}; l = gg. value + ii. value + mm. value; "style =" width: 25 "class =" bu "> <input type =" button "value =" m "name =" mm "oncli Ck = "if (this. value = 'M') {this. value = '';} else {this. value = 'M';}; l = gg. value + ii. value + mm. value; "style =" width: 25 "class =" bu "> <input type =" button "value =" without function "onclick =" this. value = (this. value = 'function not included '? 'With function': 'Without function') "name =" fun "style =" width: 85 "class =" bu "> <input type =" button "value =" show sub-match "onclick =" this. value = (this. value = 'hide child Match '? 'Show child Match': 'hide child Match') "name =" zhip "style =" width: 85 "class =" bu "> <input type =" button "value =" class "class =" bu "onclick =" alert (the three buttons on the left side of gim are currently regular parameters, by default, all three parameters are true. Click the parameter button. If the button is left blank, the parameter is eliminated! The other two [no function] and [show submatch] are currently set for regular search. Click here to change the settings! [Generate] to quickly generate regular expressions and String Conversion code! '); "> <Input type =" button "value =" Regular Expression help "onclick =" window. showModelessDialog (location. href, document. all, 'overflow: auto; dialogHeight: 600px; dialogWidth: 700px; '); "style =" color: red; "class =" bu "> note: the sky-blue part is the primary match, the soil color is a child match! </P> <p> Expression: <input type = "text" size = "30" onfocus = "this. select (); "name =" zz "> <input type =" text "style =" width: 25px; "value =" str "onfocus =" this. select (); "name =" thename "> <input type =" text "size =" 50 "onfocus =" this. select (); "name =" tiz "> <center id =" B "> search result area </center> <br/>