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
, 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*"
.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With