[英]Notepad++ Find and Replace with Regex
This is my coding: 这是我的编码:
alpha = ["first", 55, 28]
beta = ["second", 89, 09]
gamma = ["third", 99, 40]
And this is my intended outcome: 这是我的预期结果:
first", 55, 28]
second", 89, 09]
third", 99, 40]
I've tried replace the regex of ^.*?"
with empty. But why I get this instead?: 我试过用空替换^.*?"
的正则表达式。但为什么我这样做^.*?"
, 55, 28]
, 89, 09]
, 99, 40]
Find and replace with ^.*?\\["
查找并替换为^.*?\\["
Input 输入
alpha = ["first", 55, 28]
beta = ["second", 89, 09]
gamma = ["third", 99, 40]
Result 结果
first", 55, 28]
second", 89, 09]
third", 99, 40]
The problem with ^.*?"
is that it's replacing all the content one by one ^.*?"
的问题在于它正在逐个替换所有内容
You're starting with this content 你是从这个内容开始的
alpha = ["first", 55, 28] beta = ["second", 89, 09] gamma = ["third", 99, 40]
After first replace (as expected), the content becomes this, 在第一次替换(如预期)后,内容变为此,
first", 55, 28] beta = ["second", 89, 09] gamma = ["third", 99, 40]
Now, in the next replace, the cursor is still at the start of the line. 现在,在下一次替换中,光标仍然在行的开头。 Notice that there is one more double quote "
in this line (just after the text first
), thus the RegEx is matched again and so it will again replace everything before the first double quote 请注意,还有一个双引号"
在这一行(只是文本后first
),因此正则表达式是再次匹配,所以它会再次在第一双引号替换之前的一切
, 55, 28] beta = ["second", 89, 09] gamma = ["third", 99, 40]
When you continue in this manner, you'll get the output as: 当您以这种方式继续时,您将获得输出:
, 55, 28] , 89, 09] , 99, 40]
And so use ^.*?\\["
instead of ^.*?"
所以使用^.*?\\["
而不是^.*?"
EDIT 编辑
If there are any chances that you have arrays inside your parent array, then you can use ^.*?\\=\\s*\\[\\s*"
. 如果您的父数组中有数组,那么您可以使用^.*?\\=\\s*\\[\\s*"
。
This regex will also deal with whitespace character. 这个正则表达式也将处理空白字符。
Input 输入
alpha = ["first", 55, 28]
beta = ["second", 89, 09]
gamma = ["third", 99, 40]
delta = ["fourth", ["55"], 28]
After replace 更换后
first", 55, 28]
second", 89, 09]
third", 99, 40]
fourth", ["55"], 28]
Use this regex: 使用这个正则表达式:
^[^"]*"(.*)$
The quantity in parenthesis is called a capture group , because its contents will be captured for each line in your file for which the replace operation is run. 括号中的数量称为捕获组 ,因为将为运行替换操作的文件中的每一行捕获其内容。 You want to retain this captured material, so use a replacement of \\1
in the dialog box. 您希望保留此捕获的材质,因此请在对话框中使用\\1
替换\\1
。
Here is a screen capture of how to use it: 以下是如何使用它的屏幕截图:
you could try this .*=\\s?\\[
. 你可以试试这个.*=\\s?\\[
。 of course all setting as @TimBiegeleisen showed. 当然所有设置为@TimBiegeleisen都显示出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.