function parse_url(url){ var pattern = /(\w+)=([^\#&]*)/ig; var parames = {}; url.replace(pattern,function(attr,key,value){ parames[key] = decodeURI(value); }); return parames; }
/** * @param {string} url,需要解析的url,必传 * @param {string} name,需要获取的参数名,必传 * @returns */ function getUrlParam(url,name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = url.split('?')[1].substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } var url = 'http://union.bokecc.com/player?vid=107B4753B007A47D9C33DC5901307461&siteid=29639E609A1142B0&autoStart=true&width=100%&height=100%&playerid=2025478528BA86BE&playertype=1'; console.log(getUrlParam(url,'autoStart')); // true console.log(getUrlParam(url,'width')); // 100%
var email = "helloword@163.com" var username = email.replace(/(.*)@.*/,"$1");
js实现千位分隔符代码如下:
function commafy(num) { num = num + ''; var reg = /(-?d+)(d{3})/; if(reg.test(num)){ num = num.replace(reg,'$1,$2'); } return num; }
gulp 怎么能把js里面的中文转Unicode
var fs = reuqire('fs'); var msg = fs. readFileSync('xx.js','utf-8'); var unicode = new Buffer(msg,‘uCS2’); var unicodeHex = “”; for (var i = 0; i < unicode.length; i = i + 2) { unicodeHex += utils.toHex(unicode[i]) + utils.toHex(unicode[i + 1]); }
input禁止输入除了数字意外的字符
<input type="text" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">原文链接:https://www.f2er.com/regex/359192.html