Notepad++ 记事本中复杂的查找和替换++;
我有数百个文件,其中包含如下内容,我想去掉整个文件块Notepad++ 记事本中复杂的查找和替换++;,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="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(?:.|\n)*?<\/texttool>)
你可以在这里自己试试
更新1
根据要求,以下正则表达式将仅删除包含以下属性的
-rect=“55306319,23”
:
(
- Ctrl+H
- 查找内容:
]*?\brect=“55306319,23”(?:(?!),不贪婪
\brect=“55306319,23”#字面意思
#回火贪心令牌
(?:#启动非捕获组
(?!我还需要保留一堆其他的
标记。这只是我展示的那种需要删除的标记之一。基于rect=“55306319,23”这一事实,可以做些什么吗
将始终是我想要摆脱的一个?@gtilflm我已经更新了我的答案,以符合该标准。请阅读最后的说明,如果您需要更具包容性的内容,请提供更多信息,我将看看我能做些什么。不知怎的,它抓取了更多的
标记以及其他标记。其他标记没有rect=“55306319,23”
属性。不知道为什么会发生这种情况。你能将文本文件的内容上传到PasteBin或类似的地方,然后在这里发布一个链接,让我看看吗?@gtilflm没问题。奇怪的是,Npp没有正确匹配正则表达式。它可以正常工作。
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
(<texttool.*rect=\"55\,306\,319\,23\"(?:.|\n)*?<\/texttool>)
<\btexttool.*\brect\=\"55\,306\,319\,23\"([\s\S]*?)<\/\btexttool>
<texttool\b # open tag
[^>]*? # 0 or more any character that is not >, not greedy
\brect="55,306,319,23" # literally
# Tempered greedy token
(?: # start non capture group
(?!<texttool\b) # negative lookahead, make sure we haven't same tag
. # any character
)* # end group, may appear 0 or more times
</texttool> # end tag
<grouptool id="881" rect="20,576,456,141">
<imagetool id="882" rect="349.15240478515625,581.5066528320312,111.22747039794922,132.8365936279297">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="head-set-md.png" type="CLIPART" size="20419" w="252" h="300" CRC="3224584205" />
</imagetool>
<texttool id="884" rect="30,584,214,31">
<toolstroke />
<toolcolor />
<font style="3" size="24" />
<Text>Got Audio Problems?</Text>
</texttool>
<texttool id="885" rect="55,306,319,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>Note: Audio problems can be caused</Text>
</texttool>
<imagetool id="886" rect="36.17853927612305,631.7913818359375,262.9012756347656,24.34532356262207">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="unknown.png" type="CLIPART" size="1777" w="260" h="24" CRC="2321804736" />
</imagetool>
<texttool id="887" rect="55,306,319,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>by a weak/spotty internet connection.</Text>
</texttool>
<rectangletool id="888" rect="249.5330505371093,627.7338256835938,30.33476448059082,31.446043014526367">
<toolstroke WIDTH="4.0" />
<toolcolor RGB="52224" />
<fillcolor RGB="16777215" ALPHA="0" />
</rectangletool>
</grouptool>
<grouptool id="881" rect="20,576,456,141">
<imagetool id="882" rect="349.15240478515625,581.5066528320312,111.22747039794922,132.8365936279297">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="head-set-md.png" type="CLIPART" size="20419" w="252" h="300" CRC="3224584205" />
</imagetool>
<rectangletool id="883" rect="20,576,455.0214538574219,141">
<toolstroke />
<toolcolor />
<fillcolor RGB="16777215" ALPHA="0" />
</rectangletool>
<imagetool id="886" rect="36.17853927612305,631.7913818359375,262.9012756347656,24.34532356262207">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="unknown.png" type="CLIPART" size="1777" w="260" h="24" CRC="2321804736" />
</imagetool>
<rectangletool id="888" rect="249.5330505371093,627.7338256835938,30.33476448059082,31.446043014526367">
<toolstroke WIDTH="4.0" />
<toolcolor RGB="52224" />
<fillcolor RGB="16777215" ALPHA="0" />
</rectangletool>
</grouptool>