JS regular expression examples from <>

 

//parse_url
/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/

//ignore case, the other two flags are 'g', 'm'
/^abc$/i

"into".match(/in|int/)

\d is same as [0-9], \D is same as [^0-9]

\s is same as[\f\n\r\t...], \S is same as[^...]

\w is same as [0-9A-Z_a-z]

// \1 is a reference to group 1, \2 to group2
/([A-Za-z]+)\s+\1/

//regexp class
[aeiou]

//quantifier
/w{3}/
/w{3,6}/
/w{3,}/


var m = "wwwwdddd".match(/(w{3,})(d+)/);
m should be an array ["wwwwdddd", "wwww", "dddd"]

你可能感兴趣的:(JS regular expression examples from <>)