/g, '!')" method."/> /g, '!')" method.">

Home  >  Article  >  Web Front-end  >  How to replace all specified strings in js

How to replace all specified strings in js

藏色散人
藏色散人Original
2021-02-02 14:24:2022279browse

JS method to replace all specified strings: first open the corresponding js file; then perform global replacement through the "str.replace(/\
/g, '!')" method. \>

How to replace all specified strings in js

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

js Replace all specified strings

The replace method of js only replaces the first matching character

If you want to replace globally, Use the following method (g is the global flag)

str.replace(/需要替换的字符串/g,"新字符串")
//如果有特殊符号,使用‘\’转义就行了,比如把换行符‘<br/>’替换成“!”
str.replace(/\<br\/\>/g, &#39;!&#39;)

Recommended: "js Basic Tutorial"

The above is the detailed content of How to replace all specified strings in js. For more information, please follow other related articles on the PHP Chinese website!

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