繁体   English   中英

在记事本中查找并替换多个++

[英]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.

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