Regular expressions commonly used by jquery

Source: Internet
Author: User
Quickexpr ^ (? : [^] * $ | ([W-] & 43;) $ )(? :...) Indicates a non-capturing [^ SyntaxHighlighter. all (); info & nbsp; | & nbsp;

Quickexpr =/^ (? : [^ <] * (<[Ww] +>) [^>] * $ | # ([w-] +) $ )/
(? :...) Indicates a non-capturing type.

[^ <] Indicates that it starts with "<" and contains 0 or more '<' parentheses

(<[Ww] +>) indicates a capture type starting with '<>'. It contains one or more characters.

$ Indicates the end of a character.

(# ([W-] +) indicates a capture type consisting of a string, number, _, and-

Rnotwhite =/s/
S indicates a symbol other than a blank character.

Trimleft =/^ s +/trimright =/s + $/
Left and right sides. S is a blank character. ^ The prefix indicates the start of the string, and the $ suffix indicates the end of the string.

Rdigit =/d/
Indicates a number.

Rsingletag =/^ <(w +) s */?> (? : )? $/
^ <(W +) s */?>
Start with '<', contains one to multiple characters, and ends with 0 to multiple white spaces, 0 or '/' and '>,

(? : )? $

1. non-negative integer/^ d + $/
2. Positive Integer/^ [0-9] * [1-9] [0-9] * $/
3. Non-positive integer/^ (-d +) | (0 +) $/
4. negative integer/^-[0-9] * [1-9] [0-9] * $/
5. Integer/^ -? D + $/
6. Non-negative floating point number/^ d + (. d + )? $/
7. positive floating point number/^ ([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *) $/
8. Non-Positive floating point/^ (-d + (. d + )?) | (0 + (. 0 + )?)) $/
9. negative floating point number/^ (-([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *) $/
10. Floating Point/^ (-? D +) (. d + )? $/
11. Number/^ d + (. {1} d + )? $/
12. a string consisting of 26 English letters/^ [a-za-z] + $/
13. a string consisting of 26 uppercase letters/^ [a-z] + $/
14. a string consisting of 26 lowercase letters/^ [a-z] + $/
15. string consisting of digits and 26 English letters/^ [a-za-z0-9] + $/
16. A string consisting of digits, 26 English letters, or underscores (_)/^ w + $/
17. Match All single-byte characters in a string/^ [x00-xff] + $/
18. match all double-byte characters in a string/^ [^ x00-xff] + $/
19. Whether the string contains double byte/[^ x00-xff] +/
20. email Address/^ [w-] + (. [w-] +) * @ [w-] + (. [w-] +) + $/
Or/w + ([-+.] w +) * @ w + ([-.] w +) *. w + ([-.] w + )*/
21. url/^ [a-za-z] +: // (w + (-w + )*)(. (w + (-w + )*))*(? S *)? $/
Or/http: // ([w-] +.) + [w-] + (/[w -./? % & =] *)? /
22. Regular matching Chinese characters/[u4e00-u9fa5]/
23. 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;
}
24. Match the Regular Expression of null rows/n [s |] * r/
25. Match the regular expression of the html Tag/<(. *)> .* | <(. *)/>/
26. Match the regular/(^ s *) of the first and last spaces | (s * $ )/
Application: webpage effects do not include trim functions like vbscript, so we can use this expression to implement it, as shown below:
String. prototype. trim = function (){
Return this. replace (/(^ s *) | (s * $)/g, "");
}
27. Match the IP address regular/(d +). (d + )/
Application: A javascript program that uses regular expressions to match IP addresses and converts IP addresses to corresponding values:
Function ip2v (ip ){
Re =/(d +). (d +)/g;
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 !");
}
}
In fact, it may be easier to directly use the split function for decomposition. 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 ));
28. javascript programs that remove repeated characters in strings
Var s = "abacabefgeeii ";
Var s1 = s. replace (/(.). * 1/g, "$1 ′);
Var re = new regexp ("[" + s1 + "]", "g ");
Var s2 = s. replace (re ,"");
Alert (s1 + s2); // The result is: abcefgi

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.