一个JS正则的字符串替换函数

Posted baker95935

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个JS正则的字符串替换函数相关的知识,希望对你有一定的参考价值。

直接上函数吧  不废话

function replacestring(oldstr,newstr,text)

 
      var exp = new RegExp(oldstr,g);
      var c=text.replace(exp,newstr);
      return c;

 var oldstr=world;
var newstr=cccc;
var text=Hello world, Hello world;
var aa= replacestring(oldstr,newstr,text);
 console.log(aa); 

 

以上是关于一个JS正则的字符串替换函数的主要内容,如果未能解决你的问题,请参考以下文章