复杂的Notepad ++复制,替换和插入

时间:2018-12-07 05:40:15

标签: json regex replace find notepad++

我在Notepad ++中的不同行上列出了各种不相关的字符串。

127.0.0.1
badwebsite.com
dontgohere.com

如何使用Notepad ++创建类似于以下内容的内容?

{"blocked":true,"flagged":true,"string":"127.0.0.1","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"127.0.0.1","readOnly":null,"id":null,"category":null,"enabled":null}

我基本上想复制该行的内容以再次使用。首先,我需要为此添加一个前缀:

{"blocked":true,"flagged":true,"string":"

接下来是原始行内容:

127.0.0.1

然后,我将插入以下内容:

","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"

此后,将重复该行的原始内容:

127.0.0.1

最后,我将添加以下内容:

","readOnly":null,"id":null,"category":null,"enabled":null}

我确实知道我会使用带有正则表达式的替换功能来搜索^并替换为whatever I want at the start of the line,并且会搜索$并替换为whatever I want at the end of the line 。不幸的是,我不知道如何在插入字符串时重复一行的内容。

1 个答案:

答案 0 :(得分:1)

在Notepad ++中,您可以使用Replace启用正则表达式并找到:

^(.+)$

在一行的开始和结尾之间查找一组字符,并将它们存储在捕获组中,我们可以使用替换字符串中的$1来引用它们:

{"blocked":true,"flagged":true,"string":"$1","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"$1","readOnly":null,"id":null,"category":null,"enabled":null}

输出:

{"blocked":true,"flagged":true,"string":"127.0.0.1","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"127.0.0.1","readOnly":null,"id":null,"category":null,"enabled":null}
{"blocked":true,"flagged":true,"string":"badwebsite.com","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"badwebsite.com","readOnly":null,"id":null,"category":null,"enabled":null}
{"blocked":true,"flagged":true,"string":"dontgohere.com","javaClass":"com.untangle.uvm.app.GenericRule","name":null,"description":"dontgohere.com","readOnly":null,"id":null,"category":null,"enabled":null}