JQuery replaces the string of instance code

  • 2020-03-29 23:40:32
  • OfStack


function replace()
{
   var str="tao zhang yi love liu weng ling";
   re=new RegExp("l","g");
   var newstart=str.replace(re,"t");
   alert(newstr);
}

Results: "tao zhang yi tove tiu weng ting" pops up;

Explanation: The first parameter in re=new RegExp("l","g") is the string you want to replace. The second parameter is the string you want to replace.

Str.replace (re,"t") the string you want to modify for the second argument in str.replace(re,"t").


Related articles: