C #:
E-Mail Regular Expression
^ ([/W-/.] +) @ (/[0-9] {1, 3 }/. [0-9] {1, 3 }/. [0-9] {1, 3 }/.) | ([/W-] + /.) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (/]?) $
IP address Regular Expression judgment:
^ (/D {1, 2} | 1/D/d | 2 [0-4]/d | 25 [0-5])/.) {3} (/d {1, 2} | 1/D/d | 2 [0-4]/d | 25 [0-5]) $
MAC address regular:
^ ([0-9a-f] {2}-) {5} [0-9a-f] {2} $
Datetime regular (0000-00-00 00:00:00. 000 | 0000/00/00 00:00:00. 000)
"[1-2] {1} [0-9] {3} (-| //) {1} ([0]? [1-9] {1}) | (1 [0-2] {1}) (-| //) {1} ([0]? [1-9] {1}) | ([1-2] {1} [0-9] {1 }) | (3 [0-1] {1}) ([0-1] {1} [0-9] {1 }) | 2 [0-3] {1}) ([0-5] {1} [0-9] {1 }) :( [0-5] {1} [0-9] {1 })(/. [0-9] {3 })?)?)?)? $
Others:
Regular Expression matching Chinese characters: [/u4e00-/u9fa5]
Match double-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 ;}
Regular Expression for matching empty rows:/n [/S |] */R
Regular Expressions matching HTML tags:/<(. *)>. * </1> | <(. *)/>/
Regular Expression matching spaces at the beginning and end: (^/S *) | (/S * $)
Application: JavaScript does not have trim functions like VBScript. We can use this expression to implement it, as shown below:
String. Prototype. Trim = function ()
{
Return this. Replace (/(^/S *) | (/S * $)/g ,"");
}
Match the regular expression of the email address:/W + ([-+.] /W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W + )*
The regular expression matching the URL: http: // ([/W-] +/.) + [/W-] + (/[/W -./? % & =] *)?
Javascript programs that extract file names from URLs using regular expressions. the following result is page1.
S = "http://www.9499.net/page1.htm"
S = S. Replace (/(. * //) {0,} ([^/.] +). */ig, "$2 ")
Alert (s)
Use regular expressions to restrict text box input in a webpage form:
You can only enter Chinese characters using regular expressions: onkeyup = "value = value. replace (/[^/u4e00-/u9fa5]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/u4e00-/u9fa5]/g ,''))"
You can only enter the full-width characters: onkeyup = "value = value. replace (/[^/uff00-/Uffff]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/uff00-/Uffff]/g ,''))"
Use a regular expression to limit that only numbers can be entered: onkeyup = "value = value. replace (/[^/d]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/d]/g ,''))"
You can only enter numbers and English letters using regular expressions: onkeyup = "value = value. replace (/[/W]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/d]/g ,''))"
^/D + $ // match a non-negative integer (positive integer + 0)
^ [0-9] * [1-9] [0-9] * $ // match a positive integer
^ (-/D +) | (0 +) $ // match a non-positive integer (negative integer + 0)
^-[0-9] * [1-9] [0-9] * $ // match a negative integer
^ -? /D + $ // match the integer
^/D + (/./d + )? $ // Match non-negative floating point number (Positive floating point number + 0)
^ ([0-9] + /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] */. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // matches the Positive floating point number
^ (-/D + (/./d + )?) | (0 + (/. 0 + )?)) $ // Match a non-Positive floating point number (negative floating point number + 0)
^ (-([0-9] + /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] */. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // matches a negative floating point number.
^ (-? /D +) (/./d + )? $ // Match floating point numbers
^ [A-Za-Z] + $ // match a string consisting of 26 English letters
^ [A-Z] + $ // match a string consisting of 26 uppercase letters
^ [A-Z] + $ // match a string consisting of 26 lowercase letters
^ [A-Za-z0-9] + $ // match a string consisting of digits and 26 letters
^/W + $ // match a string consisting of digits, 26 English letters, or underscores
^ [/W-] + (/. [/W-] +) * @ [/W-] + (/. [/W-] +) + $ // match the email address
^ [A-Za-Z] +: // match (/W + (-/W + )*)(/. (/W + (-/W + )*))*(/? /S *)? $ // Match the URL