How to replace a line, which has a specific text, with the content of a specific line?
-
Nobody uses such quotation marks here
“name”: “noname”
`red`
red
Red doesn’t work everywhere -
It seems that you feel offended when someone gives you an well-intentioned advice.
Why is that?
If I copy your regex solution, I get, for example“name”
instead of"name"
and thus your solution is corrupted.
If, as @TerryR recommends, you wrap your solution in ` or use a code tag, this will not happen.
What is the problem here? -
@Ekopalypse
Don’t overdo it.
I don’t feel offended at all.
This is due to the short texts, but it is best to translate them.Only such quotation marks are correct
"name": "noname"
If I copy
I’ll get
-
@Pan-Jan said in How to replace a line, which has a specific text, with the content of a specific line?:
Only such quotation marks are correct
First, that’s false. It is perfectly reasonable for a question to include literal curly-quotes / smart-quotes in the question and/or answer.
But moving on to your general thought, which seems to be “people usually don’t have text with curly quotes, so everyone – whether the person asking the question or the person answering – should somehow know that they need to mentally convert curly quotes into ASCII quotes”:
let’s try out a couple scenarios. There will be three people in these scenarios: @QuestionAsker, @NoRedAnswer, and @YesRedAnswer.
-----
scenario 1, with @NoRedAnswer
@QuestionAsker says:
I have text, and want to strip out anything that’s inside quotes with no spaces:
This will remove quotes: "NoSpaces" This will keep quotes: "This has spaces"
After running search-and-replace, I want
This will remove quotes: NoSpaces This will keep quotes: "This has spaces"
@NoRedAnswer replies:
Use the search term “(\w*)” and replace with $1
@QuestionAsker says:
Sorry, that didn’t work. I tried both
(\w*)
like you said, and tried“(\w*)”
, but neither of them changed my text any.The @QuestionAsker didn’t understand the answer, because @NoRedAnswer didn’t format the answer using the forum’s formatting tools. This caused confusion and delay.
scenario 2: same circumstance, but @YesRedAnswer
@QuestionAsker says:
I have text, and want to strip out anything that’s inside quotes with no spaces:
This will remove quotes: "NoSpaces" This will keep quotes: "This has spaces"
After running search-and-replace, I want
This will remove quotes: NoSpaces This will keep quotes: "This has spaces"
@YesRedAnswer replies:
Use the search term
"(\w*)"
and replace with$1
, with Search Mode set to regular expression@QuestionAsker says:
Great, @YesRedAnswer! That worked on the first try! Thanks for your help. ++@YesRedAnswer
-----
As you should be able to see, the answer that did use
red text
for the regular expression was much more helpful, even though both people who answered came up with the same working regex.In the end, it’s your choice how to answer (or ask) questions in this forum. But you can choose to (1) make it easier for the others to understand you, or you can choose to (2) skip the red text and black text boxes, and make the person you’re helping (or the person you’re asking) try to figure out what you really meant, and probably get it wrong. We are just advising that you use style (1) rather than (2).
-
Got it … don’t put patterns in quotation marks
Only such quotation marks are correct “”
If necessary, use only such quotation marks “”But there is something I don’t understand.
Maybe it’s the translation’s fault.“in quotation marks”
I get it this way … you should remove the quotes:
"ABC"
and will be:
""
-
This post is deleted! -
@Pan-Jan said in How to replace a line, which has a specific text, with the content of a specific line?:
Got it … don’t put patterns in quotation marks
Unfortunately, you completely misunderstood. It appears the language barrier is too big.
I will say it one more time. I will try to use short sentences. Hopefully your translator will understand.
- Put regex inside ` marks to make them red. This makes regex display as literal characters for the forum, without being edited.
- My example had quote marks as part of the regex, which is valid.
- Always use the quote marks you mean.
-
@Yudi_Kondo said in How to replace a line, which has a specific text, with the content of a specific line?:
@Terry-R Ok. There are 300 files that need to be modified and lines with the text “name”: “noname”, always appear after line 6.
Here one of the files:
01{ 02 "id": "Abomasnow", 03 "spawnInfos": [ 04 { 05 "spec": { 06 "name": "Abomasnow", 07 "growth": 6 08 }, 09 "minLevel": 40, 10 "maxLevel": 45, 11 "typeID": "pokemon", 12 "rarity": 8.0 13 }, 14 { 15 "spec": { 16 "name": "noname", 17 "growth": 6 18 }, 19 "stringLocationTypes": [ 20 "Land" 21 ], 22 "minLevel": 50, 23 "maxLevel": 50, 24 "typeID": "pokemon", 25 "tags": [ 26 "safari" 27 ], 28 "rarity": 120.0 29 }
Here line 16 would become line 06
And as for the solution that switched the lines, I was wrong. I used a macro the last time I edited these files
you cannot add pokemon add according to these rules
-
To replace a line, which has a specific text, with the content of a specific line:
-
Open your document in Microsoft Word
-
Select the paragraph that you want to replace with another text
-
Under the Home tab, click on the Replace tab
-
Type in the text that you want to replace, and then click on Search button
-
Click on Replace All button to replace all occurrences of your text with the new one
-
-
Hello, @yudi_kondo, @terry-r and All,
@yudi_kondo, I’m back to your initial question :
I need all lines that have the text : “name”: “noname”,
to be replaced by the contents of line 6
Then, assuming that exists only
1
string"noname"
per file and given the INPUT text below :01{ 02 "id": "Abomasnow", 03 "spawnInfos": [ 04 { 05 "spec": { 06 "name": "Abomasnow", 07 "growth": 6 08 }, 09 "minLevel": 40, 10 "maxLevel": 45, 11 "typeID": "pokemon", 12 "rarity": 8.0 13 }, 14 { 15 "spec": { 16 "name": "noname", 17 "growth": 6 18 }, 19 "stringLocationTypes": [ 20 "Land" 21 ], 22 "minLevel": 50, 23 "maxLevel": 50, 24 "typeID": "pokemon", 25 "tags": [ 26 "safari" 27 ], 28 "rarity": 120.0 29 }
I think that this more simple regex S/R is enough to perform the goal :
SEARCH
(?-is)\A((?:.+\R){5}\d+(.+\R))((?:.+\R)+\d+).+"noname".+\R
REPLACE
\1\3\2
You should be left with this OUTPUT text :
01{ 02 "id": "Abomasnow", 03 "spawnInfos": [ 04 { 05 "spec": { 06 "name": "Abomasnow", 07 "growth": 6 08 }, 09 "minLevel": 40, 10 "maxLevel": 45, 11 "typeID": "pokemon", 12 "rarity": 8.0 13 }, 14 { 15 "spec": { 16 "name": "Abomasnow", 17 "growth": 6 18 }, 19 "stringLocationTypes": [ 20 "Land" 21 ], 22 "minLevel": 50, 23 "maxLevel": 50, 24 "typeID": "pokemon", 25 "tags": [ 26 "safari" 27 ], 28 "rarity": 120.0 29 }
Where only the line
16
is changed from :16 "name": "noname",
to :
16 "name": "Abomasnow",
In order to fully understand my regex S/R, here is the free-spacing version, using the
(?x)
in-line modifier :(?x-is) # FREE-SPACING mode and DOT match STANDARD characters ONLY \A # From BEGINNING of CURRENT file ( # BEGINING of group 1 ( Lines 1 to 6 ) (?: .+ \R){5} # First NON-CAPTURING group ( Lines 1 to 5 ) \d+ # BEGINNING of line 06 ( Number ) ( .+\R ) # Group 2 ( REMAINDER of the line 06 with its LINE-BREAK ) ) # End of group 1 ( # BEGINNING of group 3 (?: .+\R )+ \d+ # Second NON-CAPTURING group ( ENTIRE Lines 07 to 15 + BEGINNING of line 16 or any OTHER line ) ) # END of group 3 .+ "noname" .+ \R # Remainder of line 16, containing the string "noname", with that CASE or any OTHER line
In case that there’s no leading numbers, my regex S/R becomes :
SEARCH
(?-is)\A((?:.+\R){5}(.+\R))((?:.+\R)+).+"noname".+\R
REPLACE
\1\3\2
or, in free-spacing mode :
(?x-is) # FREE-SPACING mode and DOT match STANDARD characters ONLY \A # From BEGINNING of CURRENT file ( # BEGINING of group 1 ( Lines 1 to 6 ) (?: .+ \R){5} # First NON-CAPTURING group ( Lines 1 to 5 ) ( .+\R ) # Group 2 ( Line 06 with its LINE-BREAK ) ) # End of group 1 ( # BEGINNING of group 3 (?: .+\R )+ # Second NON-CAPTURING group (ENTIRE Lines 07 to 15 ) ) # END of group 3 .+ "noname" .+ \R # line 16, containing the string "noname", with that CASE or any OTHER line
Best Regards,
guy038
-
This is a Notepad++ forum. Notepad++ is perfectly capable of doing the search and replace. There is no reason, in this Forum, to recommend switching to a proprietary, costly word processor to do a simple search-and-replace rather than using the free-and-open-source Notepad++ text editor that is that is the subject of this forum and has all the features necessary to make the change requested.