function GetQueryString(str, name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = str.match(reg);
if(r!=null)return unescape(r[2]); return null;
}
Do I have to use regular expressions? This can also be done using url and querystring.
var url = require('url');
var qs = require('querystring');
function getQuery(_url_){
return qs.parse(url.parse(_url_).query);
}
var q = getQuery('http://1dwen.cn/index.php/brand/hot_product?id=2');
console.log(q.id);
Let me write a function that takes parameter values
var str='http://1dwen.cn/index.php/brand/hot_product?id=2'
function getParmValue(str){
if(str.indexOf('?')==-1){
return false;
}else{
var s=str.slice(str.indexOf('?')+1);
var arr=s.split('=');
return arr[1];
}
}
getParmValue(str);
http://1dwen.cn/index.php/bra...
Do I have to use regular expressions? This can also be done using url and querystring.
Let me write a function that takes parameter values