在特定条件下查找并替换成对中的每第二行

Find and Replace every 2nd line in a pair under certain conditions

我希望在 Notepad++ 中使用以下示例替换多行(数千行):

<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\comporgel.zip</ApplicationPath>
<CommandLine />
<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\Christmas.zip</ApplicationPath>
<Photo />
<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\spruce1.zip</ApplicationPath>
<CommandLine />
<ApplicationPath>F:\Objects\Trees\Conifers\North America\East\spruce1.zip</ApplicationPath>
<CommandLine />

我需要搜索包含子文件夹 \West\ 的所有行,并仅在匹配 <CommandLine /><CommandLine>trees -nowindow</CommandLine>

时才替换紧随其后的行

输出应如下所示:

<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\comporgel.zip</ApplicationPath>
<CommandLine>trees -nowindow</CommandLine>
<ApplicationPath>F:\Objects\Trees\Confiers\North America\West\Christmas.zip</ApplicationPath>
<Photo />
<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\spruce.zip</ApplicationPath>
<CommandLine>trees -nowindow</CommandLine>
<ApplicationPath>F:\Objects\Trees\Conifers\North America\East\spruce1.zip</ApplicationPath>
<CommandLine />

我所知道的就是转到搜索 -> 替换,但我不知道如何找到它:

<ApplicationPath>F:\Objects\Trees\Conifers\North America\West\RANDOMTEXT.zip</ApplicationPath>
<CommandLine />

并仅将命令行部分替换为 <CommandLine>trees -nowindow</CommandLine>

假设您使用的是类似 Notepad++ 的东西,它支持完整的正则表达式替换,您可以尝试以下操作:

Find:    (<ApplicationPath>.*\West\.*<\/ApplicationPath>\n)<CommandLine \/>
Replace: <CommandLine>trees -nowindow</CommandLine>

这里是demo.

将搜索设置为正则表达式模式:

查找内容:^(<ApplicationPath>[^<]*?\West\[^<]+?</ApplicationPath>\r?\n)<CommandLine />

替换为:<CommandLine>trees -nowindow</CommandLine>