Basic regular expression

xiaoxiao2021-03-06  98

(/ D {3} - | / d {4} -)? (/ d {8} | / d {7})? // Domestic phone ^ [1-9] * [1-9] [0-9 ] * $ // Tencent QQ ^ [// w -] (//. [// w -] ) * @ [// w -] (//. [// w -] ) $ // email address ^ [A-ZA-Z] : / / (// w // w ) *) (// w // w ) *) * (//? // s *)? $ // URL ^ / D $ // Non-negative integer ^ [0-9] * [1-9] [0-9] * $ 正 正 整 ^ ((- // D ) | (0 )) $ // Non - integer ^ - [0-9] * [1-9] [0-9] * $ // Negative integer ^ -? // D $ // integer ^ // D (////d )? $ // Non-looted point ^ (([0-9] //////////////////////////////ww [0-9] * [1-9] [0-9] *) | ([0 -9] * [1-9] [0-9] ) | ([0-9] * [1-9] [0-9] *)) $ 正 正Floating point ^ ((- // D (//// D )?) | (0 (//. 0 )?)) $ // Non-positively floating point number ^ (- (([0-9] //. [0-9] * [1-9] *) | ([0-9] * [1-9] [0-9] * ///. [0-9] ) | ([0-9] * [1-9] [0-9] *))) $ // Endless floating point ^ (-? // d ) (// D )? $ // float Point ^ [A-ZA-Z] $ // String of 26 English letters ^ [AZ] $ // String ^ [AZ] $ // by 26 English letters 26 English letters of lowercase string ^ [a-za-z0-9] $ // string of characters and 26 English letters, ^ // w $ // by numbers, 26 English letters or String composed of underscores

Regular expressions matching Chinese characters: [/ u4e00- / u9fa5]

Match double-byte characters (including Chinese characters): [^ / X00- / XFF]

Regular expression of matching blank line: / n [/ s |] * / r

Matching the regular expression of HTML tag: / <(. *)>. * | <(. *) //> /

Regular expression of matching the first tail space: (^ / s *) | (/ s * $) (/ s * $) (like Vbscript Trim function)

Match the regular expression of the email address: / w ([- .] / W ) * @ / w ([-.] / W ) * /. / W ([-.] / W ) *

Matching URL URL regular expressions: http: // ([/ w-] /.) [/ W-] (/ [/ w- ./?%&=]*)?

Match the regular expression of the IP address: regex.ismatch (Strin, @ "^ (/ d {1, 2} | 1 / d / d | 2 [0-4] / d | 25 [0-5]) /. (/ D {1,2} | 1 / d / d | 2 [0-4] / d | 25 [0-5]) /. (/ d {1, 2} | 1 / d / d | 2 [ 0-4] / d | 25 [0-5]) /. (/ D {1, 2} | 1 / d / d | 2 [0-4] / d | 25 [0-5]) $ ") ;

-------------------------------------------------- ------------------------ The following is example:

Use the regular expression to limit the text box in the text box in the web form:

Use the regular expression restrictions can only be entered in Chinese: οNKEYUP = "value = value.replace (/ [^ / U4E00- / U9FA5] / g, '')" onbeforepaste = "ClipboardData.SetData ('Text', ClipboardData.Getdata) 'Text'). Replace (/ [^ / U4E00- / U9FA5] / g, '')) "1. Use the regular expression limit can only enter a full-corner character: οnkeyup =" value = value.replace (/ [^ / UFF00- / uffff] / g, '') "onbeforepaste =" clipboardData.setdata ('text', clipboardData.getdata ('text'). Replace (/ [^ / uff00- / uffffff) / g, ')) "

2. Use the regular expression to limit only numbers: οnkeyup = "value = value.replace (/ [^ / d] / g, '')" onbeforepaste = "ClipboardData.SetData ('Text', ClipboardData.Getdata) Text '). Replace (/ [^ / d] / g,'))

3. Use the regular expression to limit only numbers and English: οnkeyup = "value = value.replace (/ [/ w] / g, '')" onbeforepaste = "gBEFOREPASTE =" ClipboardData.SetData ('Text', ClipboardData.GetData) 'Text'). Replace (/ [^ / D] / g, ')) ")

4. Calculate the length of the string (a double-byte character length 2, ASCII characters 1)

String.prototype.len = function () {return this.Replace ([^ / X00- / XFF] / g, "aa"). Length;}

5. There is no TRIM function like VBScript in JavaScript, we can use this expression to be implemented, as follows:

String.prototype.trim = function () {Return this.Replace (/ (^ / s *) | (/ s * $) / g, "");

Using regular expressions to decompose and convert IP addresses:

6. The following is to match the IP address using the regular expression and convert the IP address into a corresponding value of JavaScript:

Function IP2V (IP) {RE = / (/ d ) /. (/ d ) /. (/ d ) /. (/ d ) / g // Match the regular expression IF of the IP address (Re.Test (IP) $ 1 * Math.Pow (255, 3)) Regexp. $ 2 * Math.Pow (255, 2)) Regexp. $ 3 * 255 regexp. $ 4 * 1} else {throw new error (" Not a correct IP address! ")}}

However, the above program does not use a regular expression, and directly use the SPLIT function to decompose may be simpler, the program is as follows:

转载请注明原文地址:https://www.9cbs.com/read-104979.html

New Post(0)