Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除标记Regex之间的所有内容_Javascript_Regex - Fatal编程技术网

Javascript 删除标记Regex之间的所有内容

Javascript 删除标记Regex之间的所有内容,javascript,regex,Javascript,Regex,我正在尝试删除任何html标记中的所有内容: 输入: <a class="yoyo"> <h1 id="test"> hello </h1> </a> 你好 奇怪的例子,但很好 输出: <a><h1>hello</h1></a> 你好 我试过/()/gmi,但它不起作用 如果你有任何线索的话。 谢谢 在你发表评论之后,为了解释更多,我废弃了一个网站,我有一个.txt文件,我想清理一下。它将包

我正在尝试删除任何html标记中的所有内容:

输入:

<a class="yoyo"> <h1 id="test"> hello </h1> </a>
你好 奇怪的例子,但很好

输出:

<a><h1>hello</h1></a>
你好 我试过
/()/gmi
,但它不起作用

如果你有任何线索的话。 谢谢


在你发表评论之后,为了解释更多,我废弃了一个网站,我有一个.txt文件,我想清理一下。它将包含一个页面的整个html,我想清理每个html标记并删除空格。
因此,任何之间的所有内容都应该删除。

下面的正则表达式如何:

<[^>]*>
]*>

您必须连接所有匹配项。

使用DOM方法进行连接。循环所有元素,迭代属性并删除它们

let cont=document.getElementById('demo-container'),
els=cont.queryselectoral('*');
[].slice.call(els).forEach(el=>{
[].slice.call(el.attributes).forEach(attr=>{
el.removeAttribute(属性名称);
})
});
console.log(cont.innerHTML)

你好

你能详细说明一下吗?你可以在html标记中包含一百万个html标记,你到底想做什么?正则表达式是否也必须将“hello”改为“sallt”并删除空格?只是开个玩笑,但是我对空格是认真的。不要用正则表达式。为什么不使用JS实用程序(特别适合解析和操作标记),而不是使用正则表达式()链接到“那篇文章”George!!!如果我错了,摇拳头告诉我,但似乎你的正则表达式删除了标签之间的所有内容。例如,hello变成或者我想删除标记中的所有内容,所以hello变成我得到它。这个怎么样:(]*(>)您必须在这个组中连接匹配组。