[英]Multiple find and replace in notepad++
我在Notepad ++中使用正则表达式来查找<span class="bold">(.*?)</span>
并将其替换为<strong>\\1</strong>
和<span class="italic">(.*?)</span>
和<i>\\1</i>
。 我必须对许多文档执行此操作,并且想知道是否可以通过一次查找和替换来完成这两项操作。
您可以考虑使用sed通过单个命令行完成此任务。 下面的示例将在给定目录中的所有.txt
文件中查找/替换多个模式/替换。
sed -e 's/pattern1/replacement1/g;s/pattern2/replacement2/g' *.txt
要实际替换这些模式,请使用i
选项。 -r
选项允许扩展正则表达式。
sed -i -re 's!<span class="bold">(.*?)</span>!<strong>\1</strong>!g;s!<span class="italic">(.*?)</span>!<i>\1</i>!g' *.txt
我想出了一些办法使它起作用,但是它只能使<span class="bold">
变成<b>
而不是<strong>
因为它捕获了类中的一个字符:
<span class="(b(?=old)|i(?=talic))[^"]+">(.*?)<\/span>
<\1>\2</\1>
说明:
<span class="
( (?# start capture group for new element)
b (?# match b...)
(?=old) (?# followed by old)
| (?# OR)
i (?# match i)
(?=talic) (?# followed by italic)
) (?# end capture group)
[^"]+ (?# match non-" characters that were found in lookaheads)
">
(.*?) (?# lazily capture the contents of the span)
<\/span>
但是您应该能够使用Notepad ++ 在所有文件中查找/替换 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.