Home  >  Article  >  Web Front-end  >  jQuery replace string (example code)_jquery

jQuery replace string (example code)_jquery

WBOY
WBOYOriginal
2016-05-16 17:15:561158browse

Copy code The code is as follows:

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

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

Explanation: re=new RegExp("l","g") The first parameter is the string you want to replace, and the second parameter refers to the replacement All of them, the second parameter can also be set to ("i"), which means only the first string is replaced.

The second parameter in str.replace(re, "t") is the string you want to modify.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn