C # Regular Expression Summary

Source: Internet
Author: User
Username [\ W \-] {3, 12} 3-12 characters (including English letters, numbers ,'-','_') password [\ X21-\ x7e] {3, 8} 3-8 common characters (0x21 to 0x7e) age 1 [0-2] \ d | \ D {129} maximum years old date (19 | 20) \ D {2} [/\ s \-\.] * (0 [1-9] | 1 [0-2] | [1-9]) [/\ s \-\.] * (0 [1-9] | 3 [01] | [12] [0-9] | [1-9]) date without time, no handling case (19 | 20) \ D {2} [/\ s \-\.] * (0 [1-9] | 1 [0-2] | [1-9]) [/\ s \-\.] * (0 [1-9] | 3 [01] | [12] [0-9] | [1-9]) ([\ s] * (2 [0-3] | [01]? \ D) (: [0-5]? \ D) {0, 2 })? Date and time that can contain time (2 [0-3] | [01]? \ D) (: [0-5] \ D) {0, 2} does not contain the date (19 | 20) \ D {2} [/\ s \-\.] * (0 [1-9] | 1 [0-2] | [1-9]) [/\ s \-\.] * (0 [1-9] | 3 [01] | [12] [0-9] | [1-9]) [\ s] * (2 [0-3] | [01]? \ D) (: [0-5] \ D) {0, 2} must contain the date ID card \ D {18} | \ D {15} 15 or 18 digital emails \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * URL http: // ([\ W-] + \.) + [\ W-] + (/[\ W -. /? % & =] *)? Only HTTP amount \ D + [\.]? \ D {0, 2} allows you to enter a digital phone number (\(? \ D {3, 4 }\)?)? [\ S-]? \ D {7, 8} [\ s-]? \ D {} is compatible with fixed-line and mobile phones. It supports area code, "-", and extension Chinese name [\ u3000-\ u9fa5 \ x20] {2, 4}; Length: 2-4, any character string ^. {} any character ranging from 1 to 16 can only contain numbers: "^ [0-9] * $ ". Only n digits can be entered: "^ \ D $ ". You can only enter at least N digits: "^ \ D {n,} $ ". Only M ~ can be input ~ N-digit :. "^ \ D {M, N }$" only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $ ". Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $ ". Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $ ". Only a non-zero positive integer can be entered: "^ \ +? [1-9] [0-9] * $ ". Only a non-zero negative integer can be entered: "^ \-[1-9] [] 0-9" * $. Only 3 characters can be entered: "^. {3} $ ". You can only enter a string consisting of 26 English letters: "^ [A-Za-Z] + $ ". You can only enter a string consisting of 26 uppercase letters: "^ [A-Z] + $ ". You can only enter a string consisting of 26 lower-case English letters: "^ [A-Z] + $ ". You can only enter a string consisting of a number and 26 English letters: "^ [A-Za-z0-9] + $ ". You can only enter a string consisting of digits, 26 English letters, or underscores (_): "^ \ W + $ ". Verify the User Password: "^ [A-Za-Z] \ W {5, 17} $". The correct format is: start with a letter, with a length of 6 ~ It can only contain characters, numbers, and underscores. Check whether ^ % & ',; =? $ \ "And other characters:" [^ % & ',; =? $ \ X22] + ". Only Chinese characters can be entered: "^ [\ u4e00-\ u9fa5] {0,} $" verification email address: "^ \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * $ ". Verify interneturl: "^ [url = http: // ([/] http: // ([/url] \ W-] + \.) + [\ W-] + (/[\ W -. /? % & =] *)? $ ". Verification phone number: "^ (\ D {3, 4}-) | \ D {3.4 }-)? \ D {7,8} $ "correct format:" XXX-XXXXXXX "," XXXX-XXXXXXXX "," XXX-XXXXXXX "," XXX-XXXXXXXX "," xxxxxxx "and" XXXXXXXX ". Verify the ID card number (15 or 18 digits): "^ \ D {15} | \ D {18} $ ". 12 months of verification: "^ (0? [1-9] | 1 [0-2]) $ "the correct format is:" 01 "~ "09" and "1 "~ "12 ". 31 days of verification for a month: "^ (0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $ "the correct format is;" 01 "~ "09" and "1 "~ "31 ". Use a regular expression to restrict text box input in a webpage form: Use a regular expression to restrict only Chinese characters. Use a regular expression to restrict only full-width characters. Use a regular expression to restrict only numbers: use a regular expression to limit that only numbers and English characters can be entered: Use a regular expression to extract the JavaScript code of the file name from the URL address. Program , The following result is page1 S = "http://www.9499.net/page1.htm" s = S. replace (/(. * \/) {0,} ([^ \.] + ). */ig, "$2") Alert (s) matches two-byte characters (including Chinese characters): [^ \ x00-\ xFF] application: calculate the length of a string (two-byte length Meter 2, ASCII character meter 1) string. prototype. len = function () {return this. replace ([^ \ x00-\ xFF]/g, "AA "). length;} The regular expression matching empty rows: \ n [\ s |] * \ r matches the regular expression marked in HTML:/<(. *)>. * <\/\ 1> | <(. *) \/>/match the regular expression of the first and last spaces: (^ \ s *) | (\ s * $) string. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/G, "");} use regular expressions to break down and convert IP addresses. Below is a javascript program that uses regular expressions to match IP addresses and convert IP addresses to corresponding values: function ip2v (IP) {Re =/(\ D + )\. (\ D + )\. (\ D + )\. (\ D +)/g // The regular expression that matches the IP address if (Re. test (IP) {return Regexp. $1 * Math. pow (255, 3) + Regexp. $2 * Math. pow (255, 2) + Regexp. $3*255 + Regexp. $4*1} else {Throw new error ("not a valid IP address! ")} However, if the above program does not use regular expressions, it may be simpler to use the split function directly. The program is as follows: var IP =" 10.100.0000168 "IP = IP. split (". ") Alert (" the IP value is: "+ (IP [0] * 255*255*255 + IP [1] * 255*255 + IP [2] * 255 + IP [3] * 1 )) symbol Description: character description \ marks the next character as a special character, an original character, or a backward reference, or an octal escape character. For example, 'n' matches the character "N ". '\ N' matches a line break. The sequence '\' matches "\" and "\ (" matches "(". ^ Matches the start position of the input string. If the multiline attribute of the Regexp object is set, ^ matches the position after '\ n' or' \ R. $ Matches the end position of the input string. If the multiline attribute of the Regexp object is set, $ also matches the position before '\ n' or' \ R. * Matches the previous subexpression zero or multiple times. For example, Zo * can match "Z" and "Zoo ". * Is equivalent to {0 ,}. + Match the previous subexpression once or multiple times. For example, 'Zo + 'can match "zo" and "Zoo", but cannot match "Z ". + Is equivalent to {1 ,}.? Match the previous subexpression zero or once. For example, "Do (ES )? "Can match" do "in" do "or" does ".? It is equivalent to {0, 1 }. N is a non-negative integer. Match n times. For example, 'O {2} 'cannot match 'O' in "Bob", but can match two o in "food. {N,} n is a non-negative integer. Match at least N 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 *'. Both {n, m} 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}" matches 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.? When this character is followed by any other delimiter (*, + ,?,, {N ,}, {n, m}), 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 '.. Match any single character except "\ n. To match any character including '\ n', use a pattern like' [. \ n. (Pattern) matches pattern and obtains this match. The obtained match can be obtained from the generated matches set. The submatches set is used in VBScript, and $0… is used in JScript... $9 attribute. To match the parentheses, use '\ (' or '\)'. (?: Pattern) matches pattern but does not get the matching result. That is to say, this is a non-get match and is not 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. (? = Pattern) Forward pre-query: matches the search string at the beginning of any string that matches pattern. 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. (?! Pattern) negative pre-query: matches the search string at the beginning of any string that does not match pattern. 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 the character that contains the pre-query, X | y matches X or Y. For example, 'z | food' can match "Z" or "food ". '(Z | f) Ood' matches "zood" or "food ". [Xyz] Character Set combination. Match any character in it. For example, '[ABC]' can match 'A' in "plain '. [^ XYZ] combination of negative character sets. Match any character not included. For example, '[^ ABC]' can match 'p' in "plain '. [A-Z] 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. [^ A-Z] 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. \ B matches a 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 '. \ B matches non-word boundaries. 'Er \ B 'can match 'er' in "verb", but cannot match 'er 'in "never '. \ CX matches the control characters specified by X. For example, \ cm matches a control-M or carriage return character. The value of X must be a A-Z or one of a-Z. Otherwise, C is treated as an original 'C' character. \ D matches a numeric character. It is equivalent to [0-9]. \ D matches a non-numeric character. It is equivalent to [^ 0-9]. \ F matches a newline. It is equivalent to \ x0c and \ Cl. \ N matches a linefeed. It is equivalent to \ x0a and \ CJ. \ R matches a carriage return. It is equivalent to \ x0d and \ cm. \ S matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v]. \ S matches any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v]. \ T matches a tab. It is equivalent to \ x09 and \ CI. \ V matches a vertical tab. It is equivalent to \ x0b and \ ck. \ W matches any word characters that contain underscores. It is equivalent to '[A-Za-z0-9 _]'. \ W matches any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'. \ XN matches n, where N 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 .. \ Num matches num, where num is a positive integer. References to the obtained matching. For example, '(.) \ 1' matches two consecutive identical characters. \ N identifies an octal escape value or a backward reference. If at least N subexpressions are obtained before \ n, n is backward referenced. Otherwise, if n is an octal digit (0-7), n is an octal escape value. \ Nm identifies an octal escape value or a backward reference. If at least one child expression is obtained before \ nm, the NM is backward referenced. If at least N records are obtained before \ nm, n is a backward reference followed by text M. If none of the preceding conditions are met, if n and m are Octal numbers (0-7), \ nm matches the octal escape value nm. \ NML if n is an octal digit (0-3) and both M and l are octal digits (0-7), the octal escape value NML is matched. \ UN matches n, where n is a Unicode character represented by four hexadecimal numbers. For example, the matching version of \ u00a9
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.