javascript运用正则表达式来去除字符串空缺
var testString=" this is the string ";
alert(testString);
testString=testString.trim(); //空缺去掉了
if(typeof String.trim=="undefined"){
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g,"");
}
}
// ^ 婚配输入的最先
// \s 婚配一个单个的空缺字符
// * 婚配0次或屡次
// $ 婚配输入的完毕
// g 对全部字符串都运用该婚配
alert(testString);
Chrome/的非空字符
var a = "Chrome/test"; // Chrome/的非空字符
if (/Chrome\/(\S+)/.test(a)) {
console.log("a");
} else {
console.log("b")
}
“`