javascript - How to use regular expressions to match ids after special symbols
三叔
三叔 2017-07-05 10:56:03
0
4
1024

str = 'http://1dwen.cn/index.php/bra...';
How to get 2 of this string;

三叔
三叔

reply all(4)
迷茫

function GetQueryString(str, name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = str.match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
扔个三星炸死你

http://1dwen.cn/index.php/bra...

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); 

代言
var str = 'http://1dwen.cn/index.php/brand/hot_product?id=2';
str.match(/^(.*)\?id=(\d+)$/)[2]
我想大声告诉你

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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template