核心代码:
//定义敏感字符
var forbiddenArray =['xx','<','>','黄色'];
//定义函数
function forbiddenStr(str){
var destString = trim(str);
var re = '';
for(var i=0;i<forbiddenArray.length;i++){
if(i==forbiddenArray.length-1)
re+=forbiddenArray[i];
else
re+=forbiddenArray[i]+"|";
}
//定义正则表示式对象
//利用RegExp可以动态生成正则表示式
var pattern = new RegExp(re,"g");
destString=destString.replace(pattern,"***");
return destString;
}
//定义敏感字符
var forbiddenArray =['xx','<','>','黄色'];
//定义函数
function forbiddenStr(str){
var destString = trim(str);
var re = '';
for(var i=0;i<forbiddenArray.length;i++){
if(i==forbiddenArray.length-1)
re+=forbiddenArray[i];
else
re+=forbiddenArray[i]+"|";
}
//定义正则表示式对象
//利用RegExp可以动态生成正则表示式
var pattern = new RegExp(re,"g");
destString=destString.replace(pattern,"***");
return destString;
}