Sublime Text 3如何按id匹配批量删除多文件中指定<section>块
Sublime Text 批量删除指定外
<section>块操作步骤 针对你给出的示例代码:
<section class="all-classes" id="section1"> content </section> <section class="all-classes" id="section2-do-not-remove-section"> content </section> <section class="all-classes" id="section3"> content </section> <section class="all-classes" id="section4"> content </section>
可按照以下步骤完成批量删除:
- 打开Sublime Text,按下
Ctrl+Shift+F(Windows/Linux)或Cmd+Shift+F(Mac)调出「多文件搜索替换」面板 - 点击搜索输入框右侧的
.*按钮,启用正则匹配模式 - 在「Find」输入框填入如下正则表达式:
<section[^>]*id="(?!section2-do-not-remove-section")[^"]*"[^>]*>[\s\S]*?</section>
正则说明:
(?!section2-do-not-remove-section)为负向预查逻辑,仅匹配id不等于指定保留值的<section>标签;[\s\S]*?为非贪婪匹配,可匹配标签内包含换行的任意内容,直到对应闭合的</section>截止,不会跨块错误匹配
- 在「Where」输入框选择你需要批量处理的HTML文件所在的文件夹,也可以直接拖入目标文件夹到输入框
- 先点击「Find」按钮预览匹配结果,确认所有需要删除的
<section>块都被正确匹配、且需要保留的section2-do-not-remove-section块没有被命中 - 确认无误后「Replace」输入框留空,点击替换按钮即可完成批量删除
内容的提问来源于stack exchange,提问作者hlguiw
相关产品推荐
相关产品推荐

