Notepad++ 正则表达式,在 170 个文件中查找特定代码

Notepad++ 正则表达式,在 170 个文件中查找特定代码

我有 170 个文件,其中有类似这样的内容:

[color=#ffb300]Name[/color]
<?php include 'test.php'; echo "$boepsffhfu"; ?>
[color=#ffb300]Name2[/color]
<?php include 'test2.php'; echo "$boepsffhfu"; ?>
[color=#ffb300]Name3[/color]
<?php include 'test3.php'; echo "$boepsffhfu"; ?>

在每个文件中,我都有不同的文本:

$boepsffhfu

并希望将所有内容替换为以下代码:

<?php
include 'hostsList.php';

foreach($hosts as $fileName => $bbCode) {
    echo $bbCode;
    include $fileName;
    echo $boepsffhfu;
}
?>

但我们必须记住,在第二个代码中,$boepsffhfu 必须与该文件中的相同。抱歉我的英语不好,但过去几个小时我一直在尝试解决这个问题,但我无法做到。PS。我安装了插件多行查找和替换。

答案1

步骤1:(使用正则表达式搜索模式)

寻找:include 'test[\d]{0,}.php'; echo "

替换为:(\ninclude 'hostsList.php';\n\nforeach\($hosts as $fileName => $bbCode\) {\n\techo $bbCode;\n\tinclude $fileName;\n\techo末尾有空格)

第2步:(此搜索模式请切换至扩展搜索模式)

寻找:"; ?>

用。。。来代替:;\n}\n?>

按照以下步骤操作将会:

[color=#ffb300]Name[/color]
<?php include 'test.php'; echo "$boepsffhfu"; ?>
[color=#ffb300]Name2[/color]
<?php include 'test2.php'; echo "$boepsffhfu"; ?>
[color=#ffb300]Name3[/color]
<?php include 'test3.php'; echo "$boepsffhfu"; ?>

变成这样:

[color=#ffb300]Name[/color]
<?php 
include 'hostsList.php';

foreach($hosts as $fileName => $bbCode) {
    echo $bbCode;
    include $fileName;
    echo $boepsffhfu;
}
?>
[color=#ffb300]Name2[/color]
<?php 
include 'hostsList.php';

foreach($hosts as $fileName => $bbCode) {
    echo $bbCode;
    include $fileName;
    echo $boepsffhfu;
}
?>
[color=#ffb300]Name3[/color]
<?php 
include 'hostsList.php';

foreach($hosts as $fileName => $bbCode) {
    echo $bbCode;
    include $fileName;
    echo $boepsffhfu;
}
?>

如果您想要保留"回显文本周围的标记,只需"从每个查找命令中删除即可。

相关内容