javascript正则表达式匹配URL

2024-12-05 02:16:35
推荐回答(3个)
回答1:

var url = 'http://xxx.com/index.php?page=1';
url = url.replace(/(http:\/\/xxx\.com\/index\.php\?page=)(\d+)/,function(){
    return arguments[1]+'2';
});

不建议使用正则,可使用location对象提取page参数进行处理

回答2:

var url="http:\/\/xxx.com/index.php?page=";
var thisUrl=url+2;

如果非用正则:

var url="http:\/\/xxx.com/index.php?page=1";
var reg=/page\=[\d]+/i;
var thisUrl=url.replace(reg,"page="+2);

回答3:

亲,一定要用正则吗?用字符串截取很简单,