最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How do I replace all occurrences of “<p>” in a string with “” in JavaScript? - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Nov 17, 2011 at 2:54 makes 6,5483 gold badges42 silver badges59 bronze badges asked Nov 16, 2011 at 14:53 Simple SimonSimple Simon 7223 gold badges9 silver badges23 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

The '/' is a special character that you have to escape it within the regex:

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.

发布评论

评论列表(0)

  1. 暂无评论