日期:2014-05-16  浏览次数:20394 次

JS regular expression examples from <<good parts>>

?

//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"]