日期:2014-05-16  浏览次数:20358 次

删除字符串
有一个字符串
var   a= "\x0fA\x0fB\x0fC\x0fD\x0fE ";
var   b= "\x0fA\x0fD ";

怎么样通过正则,把b的AD字符在a中删除!



------解决方案--------------------
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var a= "\x0fA\x0fB\x0fC\x0fD\x0fE ";
var b= "\x0fA\x0fD ";

a = a.replace(new RegExp( "[ "+ b.replace(/\x0f/g, " ") + "] ", "g "), " ").replace(/\x0f\x0f/g, "\x0f ");
alert(a)
//-->
</SCRIPT>
------解决方案--------------------
有点问题,最后一个是B中的字符的话,会替换不掉的,稍微改下
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var a= "\x0fA\x0fB\x0fC\x0fD\x0fE ";
var b= "\x0fA\x0fD ";
a=a.replace(/\x0f/g, " ").replace(new RegExp( "[ "+ b.replace(/\x0f/g, " ") + "] ", "g "), " ").replace(/[\s\S]/g,function(a){return "\x0f "+a})
//a = a.replace(new RegExp( "[ "+ b.replace(/\x0f/g, " ") + "] ", "g "), " ").replace(/\x0f\x0f/g, "\x0f ");
alert(a)
//-->
</SCRIPT>