Community
    • Login

    How to replace multiple words?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 3.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bahaa0013B
      Bahaa0013
      last edited by

      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: fruit

      Output:
      “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…

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Bahaa0013
        last edited by

        @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”.

        Bahaa0013B 1 Reply Last reply Reply Quote 3
        • PeterJonesP
          PeterJones @Bahaa0013
          last edited by

          @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.

          1 Reply Last reply Reply Quote 2
          • Bahaa0013B
            Bahaa0013 @Alan Kilborn
            last edited by

            @Alan-Kilborn
            @PeterJones

            Thanks, I found what I want:

            Find: (Lorem)|(amet)|(elit)
            Replace: (?1human)(?2friend)(?3fruit)

            PeterJonesP 1 Reply Last reply Reply Quote 2
            • PeterJonesP
              PeterJones @Bahaa0013
              last edited by

              @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).

              Bahaa0013B 1 Reply Last reply Reply Quote 2
              • Bahaa0013B
                Bahaa0013 @PeterJones
                last edited by

                @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 :>

                PeterJonesP 1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @Bahaa0013
                  last edited by PeterJones

                  @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

                  Alan KilbornA 1 Reply Last reply Reply Quote 2
                  • Alan KilbornA
                    Alan Kilborn @PeterJones
                    last edited by Alan Kilborn

                    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”.

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors