我有这样的HTML代码:
<span>This is HTML.</span> This is paragraph.
我想将span
标记与
一起替换。
我的输出将是这样的:
This is HTML.This is paragraph.
这是我尝试过的:
myvar = "<span>This is HTML.</span> This is paragraph.";
newContent = myvar.replace(/<\/?span[^>]*>/g,"");
答案 0 :(得分:0)
只需多次使用replace
。因为,除非使用正则表达式,否则它只会替换第一次出现的东西,因此不会丢失多余的
。
let initialString = '<span>This is HTML.</span> This is paragraph.';
let finalString = initialString.replace('<span>', '').replace('</span>', '').replace(' ', '');