Find and Replace several several different values all at once
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 Find And Replace Several Several Different Values All At Once
01:17 Answer 1 Score 3
01:43 Answer 2 Score 2
03:12 Accepted Answer Score 10
03:31 Answer 4 Score 41
04:08 Thank you
--
Full question
https://superuser.com/questions/211011/f...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#notepad++ #textediting #findandreplace #dreamweaver
#avk47
ANSWER 1
Score 41
Since Notepad++ 6.0 it is actually possible without scripts using the following technique:
Find: Text_1 and Replace with: Text_A
Find: Text2 and Replace with: TextB
Find: (Text_1)|(Text2)
Replace: (?1Text_A)(?2TextB)
The general syntax is:
Find: (FindA)|(FindB)|(FindC)...
Replace: (?1ReplaceA)(?2ReplaceB)(?3ReplaceC)...
?1 refers to the first captured phrase and so on.
I got this from the following answer: https://stackoverflow.com/a/16104946/287101
ACCEPTED ANSWER
Score 10
Take a look at Sed. You can easily achieve your goal by only one command line
sed -e "s/Text_1/TextA/" -e "s/Text1/TextB/" <your_file.txt>your_file_new.txt
ANSWER 3
Score 3
Using Notepad++, You can either
Open all files containing the words you want to replace and make use of Find / Replace in all open files
Use Find / Replace in files
Record a macro performing the find and replace options and play it back
ANSWER 4
Score 2
You're better off running Find & Replace twice, because you have two different replacements happening. However, there should be very little tradeoff in processing time. Consider the following:
Running Find & Replace once, searching term by term:
Get Term
Does term match? If so, replace term
Get Next Term
...
For running purposes, we'll assume it's linear and say that this runs in O(n) time.
You want to find two different terms. Running Find & Replace twice looks like:
Get Term
Does term match? If so, replace term
Get Next Term
...
Get Term
Does term match? If so, replace term
Get Next Term
...
which would take O(2x1n) time, or twice as long as searching for one term.
Searching for two terms with two replacements would theoretically look like:
Get Term
Does first term match? If so, replace first term
Does second term match? If so, replace second term
Get Next Term
...
Getting the terms does not take that much processing power, so essentially you are looking up two sets of searches for each term, giving a time of O(1x2n), running once but searching two terms.
While you would save some time not loading each term twice, you would spend more time searching each term twice, so there's little tradeoff, and since this feature would be used less often than searching one term with one replacement, application developers just assume not write that functionality.
DISCLAIMER TO PROGRAMMERS: This is a generalized example. I know it is better but I'm trying to show why that feature isn't found.