Regular expressions commonly seen in jquery

Source: Internet
Author: User

quickexpr =/^ (?: [^<]* (<[ww]+>) [^>]*$|# ([w-]+) $)/
(?:...) Represents a non-capture type

[^<] indicates that it starts with "<" and contains 0 or more ' < ' brackets

(<[ww]+>) is a catch type that starts with ' <> ' and contains one or more characters in the middle

$ indicates the end of a character

(# ([w-]+)) means a catch type, with ' # ' numbers and strings, numbers, _, and-

Rnotwhite =/s/
s represents a symbol other than a blank character

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

Rdigit =/d/
Indicates a number

Rsingletag =/^< (w+) s*/?> (?:</1>)? $/
^< (w+) s*/?>
The expression starts with ' < ', contains one to many characters, and 0 to multiple blanks, 0 or one '/' and ' > ' End,

(?:</1>)? $

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 number/^ (-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 number/^ (-?d+) (. d+)? $/
11. Digital/^d+ (. { 1}d+)? $/
12. A string/^[a-za-z]+$/consisting of 26 English letters
13. A string consisting of 26 uppercase letters/^[a-z]+$/
14. A string consisting of 26 lowercase letters/^[a-z]+$/
15. A string consisting of numbers and 26 English letters/^[a-za-z0-9]+$/
16. A string of numbers, 26 English letters, or underscores/^w+$/
17. A string that matches all Single-byte characters/^[x00-xff]+$/
18. A string that matches all two-byte-length characters/^[^x00-xff]+$/
19. Whether the string contains double-byte characters/[^x00-xff]+/
20.email address/^[w-]+ (. [ w-]+) *@[w-]+ (. [ w-]+) +$/
or/w+ ([-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) * * *
21.url Address/^[a-za-z]+://(w+ (-w+) *) (. ( w+ (-w+) *)) * (? s*)? $/
or/http://([w-]+.) +[w-]+ (/[w-/?%&=]*)?
22. Matching the regular/[u4e00-u9fa5]/of Chinese characters
23. Matching Double-byte characters (including Chinese characters)/[^x00-xff]/
Application: Computes the length of the string (a double-byte character length meter 2,ascii character 1)
String.prototype.len=function () {
Return This.replace ([^x00-xff]/g, "AA"). Length;
}
24. Matching empty rows of regular/n[s|] *r/
25. Regular/< (. *) >.*</1>|< (. *) Matching HTML tags/>/
26. Matching the right and end spaces of the regular/(^s*) | (s*$)/
Application: There is no trim function like VBScript in the web effects, we can use this expression to implement the following:
String.prototype.trim = function () {
Return This.replace (/(^s*) | ( s*$)/g, "");
}
27. Match the regular/(d+) of the IP address. (d+). (d+). (d+)/
Application: Use regular expressions to match IP addresses and translate IP addresses into JavaScript programs that correspond to numeric values:
function IP2V (IP) {
re=/(d+). (d+). (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 simpler to decompose directly with the split function, 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 program to remove repetitive characters from 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.