我可以在 sublime text 3 中同时查找和替换多个单词吗?

Can I find and replace multiple words at the same time in sublime text 3?

我想在 sublime 中同时查找和替换多个单词,例如我想同时用 word4、word5、word6 替换 word1、word2、word3,而不是分 3 个步骤进行。我可以用 sublime 做吗?如果不是,我怎么能想出一个正则表达式来做到这一点? 谢谢

您可以使用模式 word1(.*)word2(.*)word3 来匹配单词,如果要替换的单词按顺序出现,中间有或没有一些字符,并使用 word4word5word6 作为替换。

该模式使用了 3 个捕获组来匹配要替换的单词之间的字符(如果有的话)。 </code>、<code> 代表每个捕获的组。

在这里,替换模式表示匹配的文本必须替换为 word4 后跟第一个捕获组中捕获的字符的序列,即单词 1 和 word2 之间的字符,如果有的话,接着是word5等等.

在这种情况下 sed 命令可能会帮助您。

sed -i -e 's/word1/replace1/g' fileName && sed -i -e 's/word2/replace2/g' fileName && ...

这取决于您需要替换多少个单词,您可以。在您的 终端

上 运行

示例:

this is a content of file. File name is t.txt

我想用 that[=36 替换 this =] 和 fileFILE。然后命令将是:

sed -i -e 's/this/that/g' t.txt && sed -i -e 's/file/FILE/g' t.txt

输出将是:

that is a content of FILE. File name is t.txt