Notepad++找到并替换Regex。

时间:2022-09-13 23:36:39

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]

3 个解决方案

#1


9  

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

^。*?“的问题在于它正在逐个替换所有内容

  1. You're starting with this content

    你是从这个内容开始的

    alpha = ["first", 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  2. After first replace (as expected), the content becomes this,

    在第一次替换(如预期)后,内容变为此,

    first", 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  3. 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

    现在,在下一次替换中,光标仍然在行的开头。请注意,在此行中(在文本首先之后)还有一个双引号,因此RegEx再次匹配,因此它将再次替换第一个双引号之前的所有内容

    , 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  4. 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*".
This regex will also deal with whitespace character.

如果你的父数组中有数组,那么你可以使用^。*?\ = \ s * \ [\ s *“。这个正则表达式也将处理空白字符。

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]

#2


6  

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:

以下是如何使用它的屏幕截图:

Notepad++找到并替换Regex。

#3


1  

you could try this .*=\s?\[. of course all setting as @TimBiegeleisen showed.

你可以试试这个。* = \ s?\ [。当然所有设置为@TimBiegeleisen都显示出来。

#1


9  

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

^。*?“的问题在于它正在逐个替换所有内容

  1. You're starting with this content

    你是从这个内容开始的

    alpha = ["first", 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  2. After first replace (as expected), the content becomes this,

    在第一次替换(如预期)后,内容变为此,

    first", 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  3. 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

    现在,在下一次替换中,光标仍然在行的开头。请注意,在此行中(在文本首先之后)还有一个双引号,因此RegEx再次匹配,因此它将再次替换第一个双引号之前的所有内容

    , 55, 28]
    beta  = ["second", 89, 09]
    gamma = ["third", 99, 40]
    
  4. 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*".
This regex will also deal with whitespace character.

如果你的父数组中有数组,那么你可以使用^。*?\ = \ s * \ [\ s *“。这个正则表达式也将处理空白字符。

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]

#2


6  

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:

以下是如何使用它的屏幕截图:

Notepad++找到并替换Regex。

#3


1  

you could try this .*=\s?\[. of course all setting as @TimBiegeleisen showed.

你可以试试这个。* = \ s?\ [。当然所有设置为@TimBiegeleisen都显示出来。