notepad++ - Notepad ++ 中的复杂查找和替换
问题描述
我有数百个包含以下内容的文件,我想摆脱整个块。
<texttool id="468" rect="55,306,319,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>(Be sure to state the page/problem number.)</Text>
</texttool>
问题是它们都有不同的id=XXX
部分......不过其他一切都是一样的。
有没有办法进行大规模查找和替换来处理这种情况?
解决方案
使用以下正则表达式将搜索整个文件并删除所有 <texttool>
块以及其中的内容:
(<texttool(?:.|\n)*?<\/texttool>)
前
text before<texttool id="468" rect="55,306,319,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>(Be sure to state the page/problem number.)</Text>
</texttool> text after
<texttool id="468" rect="55,306,319,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>(Be sure to state the page/problem number.)</Text>
</texttool>
后
text before text after
您可以在此DEMO中亲自尝试
更新 1
根据要求,以下正则表达式将仅删除<texttool>
包含以下属性的那些 - rect="55,306,319,23"
:
(<texttool.*rect=\"55\,306\,319\,23\"(?:.|\n)*?<\/texttool>)
这是更新的 Regex DEMO。
请注意,它只会匹配那些包含该特定字符串并匹配其文字字符的块。
更新 2
我提供的正则表达式在 Notepad++ 中无法正常工作,因为它使用了基于自定义 PCRE 的正则表达式系统。这是一个对我有用的经过测试和验证的模式:
<\btexttool.*\brect\=\"55\,306\,319\,23\"([\s\S]*?)<\/\btexttool>
禁用Notepad++ 搜索窗口中的选项非常重要. matches newline
,否则该模式将不起作用,因为提供的模式与它不兼容。
推荐阅读
- android - Firebase:子事件侦听器似乎会重新加载添加的每个子对象的所有数据
- amazon-s3 - Airflow S3Hook 对象没有属性 load_bytes
- vbscript - 从具有特定值的 Parent 下的 XML 文件中获取子节点的计数
- python - Python中的字符串对象表示
- java - 为什么我在java中有这个错误
- python - 最小化权重矩阵 Keras 中非零元素的数量
- hyperledger-fabric - Azure Hyperledger Fabric:与网络交互
- python - 没有python对象的cython中的高效矩阵运算
- javascript - 谷歌可视化的多色折线图
- swift - 如何使用 Swift 通过我的应用在业务页面的“访客帖子”上发帖