当前位置: 代码迷 >> JavaScript >> JS regular expression examples from <<good parts>>
  详细解决方案

JS regular expression examples from <<good parts>>

热度:767   发布时间:2012-09-01 09:33:03.0
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"]
  相关解决方案