简体   繁体   English

如何删除 HTML 标签 VS 代码的所有实例

[英]How to remove all instances of an HTML tag VS Code

I have an HTML file that has many useless tags like empty <p> tags, and <span> 's that I want to delete.我有一个 HTML 文件,其中包含许多无用的标签,如空<p>标签和<span>我想删除的标签。 Is there any easy way to remove all <span> 's from my document without finding each one and deleting it?有什么简单的方法可以从我的文档中删除所有<span> ,而无需找到每一个并删除它?

Yes.是的。 You can use a regex to highlight all the empty elements and then just replace them with nothing.您可以使用正则表达式突出显示所有空元素,然后将它们替换为空。 The regex is <[^/>][^>]*>\s*\n*<\/[^>]+> , which includes empty tags that span multiple lines.正则表达式是<[^/>][^>]*>\s*\n*<\/[^>]+> ,其中包括跨越多行的空标签。

In VSC, when you do a search and replace ( CTRL + H ), make sure you have the "Use Regular Expression" option selected ( Alt + R ), use the above regex, and then replace it with nothing.在 VSC 中,当您进行搜索和替换( CTRL + H )时,请确保您选择了“使用正则表达式”选项( Alt + R ),使用上述正则表达式,然后将其替换为空。

Unfortunately, I don't think that there's any package or an extension that can help you with it, however, what I personally usually do in cases like such: highlight one of the tags that I need removed, reach out to Select all occurrences of current word shortcut in VS Code:不幸的是,我认为没有任何 package 或可以帮助您的扩展程序,但是,我个人在这种情况下通常会做的事情:突出显示我需要删除的标签之一, Select all occurrences of current word VS Code 中的Select all occurrences of current word快捷方式:

  • for Mac it's Cmd + F2 or fn + Cmd + F2 on the highlighted word对于 Mac,突出显示的字是 Cmd + F2 或 fn + Cmd + F2
  • for Windows its Ctrl + F2对于 Windows 其 Ctrl + F2

and with Cmd + Backspace remove all lines with the highlighted tags.并使用 Cmd + Backspace 删除所有带有突出显示标签的行。

Hit the magnifying glass icon on the left side of your screen, type in whatever you want to delete all of, and then set it to be replaced with "", then select replace all.点击屏幕左侧的放大镜图标,输入要删除的所有内容,然后将其设置为替换为“”,然后 select 全部替换。 在此处输入图像描述

I have no results, so I can't replace all, but you hopefully get the idea我没有结果,所以我不能全部替换,但希望你能明白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM