var s = "tab/{itemClass}/{itemClass}";
var itemClass = "root";
s= s.replace(/^\{[[a-zA-Z]+]\}$/g,itemClass);
//console.log(s);
var pattern = /\{[a-zA-Z]+\}/g;
//console.log(s.match(pattern));
console.log(pattern.test(s));
s= s.replace(/^\{\}$/g,itemClass);
var param = "itemClass";
var reg=new RegExp("\{"+param+"\}","g");
s= s.replace(reg,itemClass);
console.log(s);
//匹配包含数字
var accountPattern = /[0-9]+/g;
var acc = 'ST00021';
console.log(acc.match(accountPattern)); //00021
console.log(accountPattern.test(acc)); //true
var twoCasePattern = /^[a-zA-Z]{1,2}$/g; //完整匹配
console.log('label2='+twoCasePattern.test('ds'));
//去除前后空格
//1. 直接使用 trim() 方法
var str = " hello\n world ";
var strTrim = "";
var strReg = "";
console.log("str:" +str);
strTrim = str.trim();
console.log("trim()方法:" +strTrim+","+strTrim.length);
strReg = str.replace(/^\s+|\s+$/gm,'')
console.log("正则替换:" +strReg+","+strReg.length);
//
var parttern = /^[A-Z]{1,2}$/g;
console.log(parttern.test('AA'));
console.log(' ()的使用 ---------Begin。');
var str = '123bar456foo789faz';
var n = str.match(/[1-9][a-z]+/g);
console.log(n);
console.log(' ()的使用 ---------End')
function refreshToken(url,newtoken){
var urlArry = url.split('_csrf=');
if(urlArry.length>1){
var oldcsrf = urlArry[1];
console.log(oldcsrf);
if(oldcsrf.indexof('&')>0){
oldcsrf = oldcsrf.split('&')[0];
}
}
var oldCsrfStr = '_csrf='+oldcsrf;
var newCsrfStr = '_csrf='+newtoken;
url = url.replace(oldCsrfStr,newCsrfStr);
return url;
}
var url = "http://localhost/myapp?_csrf=value1";
url = refreshToken(url,"value3");
console.log(url);
var s = 'Risk level 2\nRisk level 3\nRisk level 4\nRisk';
console.log(s.split('\n'));
console