展开全部
代码如下:636f707962616964757a686964616f31333431363663
indexvar str = "http://www.nowcoder.com?key=1&key=2&key=3&test=4#hehe";
var patt1 = /key=\d/ig; //匹配key=开头,后面匹配一个数字 i表示忽略大小写 g表示尽可能多的匹配
document.write("用正则表达式取值为:" + str.match(patt1));
document.write("
")
var arr = str.match(patt1);
var result = [];
console.log(str.match(patt1)) // [key=1,key=2,key=3]
for (var i = 0; i < arr.length; i++) {
result.push(parseInt(arr[i].substr(4, 1)));
}
document.write("最终的结果为:[" + result + "]");