var content = 'http://home.com/goods/detail.html?id=845';
var rep1 = getRegExp('\?id=(.*)','i');
var rep2 = getRegExp('id=(.*)','i');
var rep3 = getRegExp('id=(.*)','i');
var code1 = content.match(rep1)[1];//取 ?id=后面所有字符串
var code2 = content.match(rep2)[1];//取 id=后面所有字符串
var code3 = content.match(rep3)[0]; //取 包含 id=及后面的字符串
console.log('?id= 后的内容为: '+code1);
console.log('id= 后的内容为: '+code2);
console.log('包含 id= 的所有内容为: '+code3);
var content = 'http://home.com/goods/detail.html?id=845';
var code1 = content.match(/\?id=(.*)/)[1];//取 ?id=后面所有字符串
var code2 = content.match(/id=(.*)/)[1];//取 id=后面所有字符串
var code3 = content.match(/id=(.*)/)[0]; //取 包含 id=及后面的字符串
console.log('?id= 后的内容为: '+code1);
console.log('id= 后的内容为: '+code2);
console.log('包含 id= 的所有内容为: '+code3);
本文详细介绍如何使用正则表达式从URL中提取特定参数值的方法,包括获取问号后的整体参数、特定参数名后的值,以及包含参数名的完整字符串。

7430

被折叠的 条评论
为什么被折叠?



