如何移除竖条"|"从HTML中使用replace()

How to remove a vertical bar "|" from HTML using replace()

本文关键字:quot replace HTML 何移      更新时间:2023-09-26

这个问题我已经有一段时间了:

v = jQuery("span.count").html().replace(/'(|')/g, "");
jQuery("span.count").html(v);

我在SO上找到了这个,它对括号很有用,但我似乎不能让它与垂直栏|一起工作。

|是在正则表达式中作为"或"使用的字符。你的regex说的是"用空字符串替换(nothing)(nothing)的任何内容"。使用反斜杠转义|,如下:

string.replace(/'|/g, "");
//              ^ Escape it!