简体   繁体   中英

How do I replace all occurrences of “</p>” in a string with “” in JavaScript?

I get errors when I try any of the following:

str = str.replace(/</p>/gm, "")
str = str.replace("</p>"/gm, "")

What am I doing wrong?

'/'是一个特殊字符,您必须在正则表达式中将其转义:

str = str.replace(/<\/p>/gm, "");
tr = str.replace(/\<\/p\>/gi, "")

You have to escape the backslash character.

str = str.replace(/<\/p>/gm, "");

See example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM