![](/img/trans.png)
[英]How do I replace all occurrences of “/” in a string with “_” in JavaScript?
[英]How do I replace all occurrences of “</p>” in a string with “” in JavaScript?
當我嘗試以下任何一種情況時,我會收到錯誤:
str = str.replace(/</p>/gm, "")
str = str.replace("</p>"/gm, "")
我究竟做錯了什么?
'/'是一個特殊字符,您必須在正則表達式中將其轉義:
str = str.replace(/<\/p>/gm, "");
tr = str.replace(/\<\/p\>/gi, "")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.