添加到包含特定单词并以 x 开头的行尾

Add to end of line that contains a specific word and starts with x

我想在我用 Notepad++ 打开的文档中以 10 开头并包含特定单词(例如 "frog")的所有行的末尾添加一些自定义文本。

到目前为止,我设法解决了第一部分。

Search: ^(10)$

Replace: ;Batteries (to add ;Batteries to the end of the line)

我现在需要的是编辑此正则表达式模式以仅识别那些也包含特定单词的行。

例如:

Before: 1050;There is this frog in the lake

After: 1050;There is this frog in the lake;Batteries

您应该在数字和行尾之间允许任何字符:

^10(.*frog.*)$

替换为 10;Batteries(我们需要添加 10 以将其保留在输出中)。

这是截图:

试试这个 查找方式:(^(10).*(frog).*) 替换为:;Battery

使用 ^(10.*frog.*)$ 作为正则表达式。将其替换为 ;Batteries

您可以使用正则表达式来匹配您想要的行:

(^(10).*?(frog).*)

.*?是一个懒惰的量词,在 frog

之前得到最小值

并替换为:

;Battery

希望对您有所帮助,