Regular expressions

xiaoxiao2021-03-17  186

"^ / D $" // Non-negative integer (positive integer 0) "^ [0-9] * [1-9] [0-9] * $" // 正 整 "" ^ ((- / d ) | (0 )) $ "// Non-positive integer (negative integer 0)" ^ - [0-9] * [1-9] [0-9] * $ "// negative integer" ^ -? / D $ "// integer" ^ / D (/. / D ) $ "// Non-looted number (positive floating point 0)" ^ (([0-9] /. [0-9] * [1-9] *) | ([0-9] * [1-9] [0-9] * /. [0-9] ) | ([0-9] * [1 -9] [0-9] *)) $ "正 正 floating point number" ^ ((- / D (/ d )?) | (0 (/. 0 )?)) $ "// Non-positively floating point (12 0) "^ ((([([0-9] /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * /. [0-9] ) | ([0-9] * [1-9] [0-9] *))) $ "// loaded point number "^ (-? / d )? $" // floating point number "^ [A-ZA-Z] $" // String consisting of 26 English letters "^ [AZ] $ "// String consisting of 26 English letters" ^ [AZ] $ "// String of 26 English letters," ^ [A-ZA-Z0-9] $ " // String "^ / W $" // consisting of numbers, 26 English letters or underscores "^ [/ w -] (/ w-] ) * @ [/ w -] (/. [/ w -] ) $ "// email address" ^ [A-ZA-Z] : // (/ w (- / w ) *) (/.(/w (-/w ) * * * (/?/s* )?? "// URL

^ [0-9A-ZA-Z / U4E00- / U9FA5] {5,16} $

Some commonly used network links: (H | H) (r | r) (e | e) (f | f) * = * ('| ")? (/ W | // | // | /.) ('| "| * |>)?

Extraction information: / w ([- .] / W ) * @ / w ([-.] / W ) * /. / W ([-.] / W ) *

Image link in extraction information: (s | s) (r | r) (c) * = * ('| ")? (/ W | // | // | /.) (' |" | * |>)?

The IP address in the extraction information: (/D )/.(/d )/.(/d )

China Mobile Number in Extraction Information: (86) * 0 * 13 / D {9}

China Fixed Phone Numbers in the extraction information: (/ D {3, 4} /) | / d {3, 4} - | / s)? / D {8}

China Telephone Numbers (including mobile and fixed telephones) in the extraction information: (/ D {3, 4} /) | / s)? / D {7,14}

China Postal Code in Extract Information: [1-9] {1} (/ D ) {5}

China ID card number in the extraction information: / d {18} | / d {15}

Extraction information in the information: / d

The number of floating point (ie, decimal) in the extraction information: (-? / D *) /.?/ d

Any number in the extraction information: (-? / D *) (/. / d )? Extract Chinese string: [/ u4e00- / u9fa5] *

Double-byte string in the extraction information (Chinese characters): [^ / X00- / XFF] *

English string in the extraction information: / w *

Can match one or more Chinese characters ^ [/ u4e00- / u9fa5] $

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

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

Application: 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;}

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

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

Regular expressions matching the first tail space: (^ / s *) | (/ s * $)

Application: 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:

Below is the JavaScript program that uses the regular expression to match the IP address and convert the IP address into the corresponding value:

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 valid 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:

VAR IP = "10.100.20.168" IP = IP.Split (".") Alert ("IP value is:" (IP [0] * 255 * 255 * 255 IP [1] * 255 * 255 IP [ 2] * 255 IP [3] * 1))

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

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

Using the regular expression to remove the algorithm program of repeated characters in the strings: [Note: This program is incorrect, the reason is seen in this post Reply]

Var s = "AbacaFgeeii" var s1 = s.Replace (/( (.). "$ 1") VAR RE = New Regexp ("[" S1 "]", "G") VAR S2 = S.Replace (re, ") ALERT (S1 S2) / / The result is: Abcefgi I originally posted a way to find an expression on 9CBS to implement the method of removing the repeating character, and I didn't find it, this is what I can think of. The simplest implementation method. The idea is to use the retrieval to remove the repeated characters, and then establish a second expression with a duplicate character, take the non-repetitive character, and the two are connected. This method may not apply for a string that requires the character sequence.

You have to extract the JavaScript program of the file name from the URL address using a regular expression. The following results are page1

S = "http://www.9499.net/page1.htm" s = s.Replace (/ (//) {0,} ([^ /.] ). * / ig, "$ 2" Alert (s)

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, '')) "

Use the regular expression to limit only full-width characters: οnkeyup = "value = value.replace (/ [^ / uff00- / uffff) / g, ')" onbeforepaste = "clipboardData.setdata (' Text ', ClipboardData.Getdata) ('text'). Replace (/ [^ / UFF00- / UFFFFF] / g, '')) "

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

Use regular expressions to limit only numbers and English: οNKEYUP = "value = value.replace (/ [/ w] / g, '')" onbeforepaste = "ClipboardData.SetData ('Text', ClipboardData.Getdata ('Text ') .Replace (/ [^ / d] / g,'))

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

New Post(0)