<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>正则表达式-敏感词过滤</title>
</head>
<body>
<script type="text/javascript">
var str='中国军队和阿扁一起办证';
var pattern=/国军|阿扁|办证/g;
//$0表示0个分组的内容
console.log(str.replace(pattern,function($0){
var result='';
for(var i=0;i<$0.length;i++){
result+='*';
}
return result;
}));
</script>
</body>
</html>
来源:CSDN
作者:weixin_40533188
链接:https://blog.csdn.net/weixin_40533188/article/details/99327120