How to replace multiple words?
-
Is there a way to replace multiple words with multiple values at the same time?
I mean like translating.
example text:
“Lorem ipsum dolor sit amet, consectetur adipiscing elit.”What I want to replace:
(this: that)
amet: friend
Lorem: human
elit: fruitOutput:
“human ipsum dolor sit friend, consectetur adipiscing fruit.”So is there any regex commands to do that?
If this future is available in notepad++ it will help so much to edit huge txt file, Instead of replacing one by one…
-
@Bahaa-Eddin-ツ
You’re talking about a “replace from list” capability.
It doesn’t exist unless scripting is used.
Try searching this forum for “replace from list”. -
@Bahaa-Eddin-ツ ,
Also, since I couldn’t find my post when I used @Alan-Kilborn’s search term, I will mention I wrote a “translation bot” script, where you put in a group of pairs in the script, then run the script, and it “translates” it. The example is English -> Some Other Language. But the same logic works for English1 -> English2 or Lorem Ipsum to English or whatever.
-
Thanks, I found what I want:
Find: (Lorem)|(amet)|(elit)
Replace: (?1human)(?2friend)(?3fruit) -
@Bahaa-Eddin-ツ ,
That will definitely work for a short list of changes.
If that’s sufficient for you, that’s great. Alan and I tend to answer assuming that the real requirements is to have a longer list than the example (which wouldn’t be practical in the alternation regex like you showed).
-
@PeterJones said in How to replace multiple words?:
That will definitely work for a short list of changes.
If that’s sufficient for you, that’s great. Alan and I tend to answer assuming that the real requirements is to have a longer list than the example (which wouldn’t be practical in the alternation regex like you showed).I think it works perfectly with long list of words too : ), But it needs some time to add +120 word, and then I have to add again 120 word to replace with…
I’m new in notepad++, That’s why I chose the easy method :>
-
@Bahaa-Eddin-ツ ,
The Find what field is character-limited to 2047 characters, so 200 words at 8 characters per word plus the three characters for
(and)and|means 2200 characters, which will not fit.But if you ever really do go to that many long words, then you have the option to switch to a scripting language as suggested above, or break it into a couple of ~2000-character expressions rather than one >2000-character expression.
But personally, if the regex is more than ~100 words, I would question my own sanity in using it, because it would be easier for me to put the 100 pairs in a readable form like the TranslationBot script than to build up a regex that long and hope I didn’t make a mistake in creating the find and replace expressions – off-by-one could be killer in that situation!
--
edit: changed from 1000 (bad memory) to 2047 (actual threshold); add third paragraph -
Find: (Lorem)|(amet)|(elit)
Replace: (?1human)(?2friend)(?3fruit)Really, if you’re going to go “long” with that syntax, you could have a script do it – create the syntax for you. But…if you’re making the scripting leap, maybe it is best to go “all the way”.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login