Community
    • Login

    is thier any posibilities to find and replace multiple words at once ?

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 4 Posters 24 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.
    • N
      neeraj10786
      last edited by

      is thier any posibilities to find and replace multiple words at once ?
      i have to find and replace 20-30 different words at one time without working one by one

      PeterJonesP CoisesC 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @neeraj10786
        last edited by PeterJones

        @neeraj10786 said in is thier any posibilities to find and replace multiple words at once ?:

        is thier any posibilities to find and replace multiple words at once ?
        i have to find and replace 20-30 different words at one time without working one by one

        20-30? Easily. 200-300: less likely to work.

        It depends on your use case:

        If you want all 20-30 words to be replaced by a single word:

        • FIND WHAT: apple|banana|cantaloupe|xyz
        • REPLACE WITH: fruit
        • SEARCH MODE = Regular Expression
        • REPLACE ALL

        It’s more fancy regex if you want to replace each of the 20-30 original words with a different word:

        • FIND WHAT: (apple)|(banana)|(cantaloupe)|(date)|(elderberry)|(fig)|(grape)|(honeydew)|(imbe)|(jackfruit)|(kiwi)|(lime)|(mango)|(nectarine)|(orange)|(peach)|(quince)|(raspberry)|(strawberry)|(tangerine)|(ugli-fruit)|(xigua)|(yangmei)|(zinfandel)
        • REPLACE WITH: (?{1}armadillo)(?{2}bat)(?{3}camel)(?{4}dolphin)(?{5}elephant)(?{6}frog)(?{7}grasshopper)(?{8}hedgehog)(?{9}iguana)(?{10}jellyfish)(?{11}kangaroo)(?{12}lion)(?{13}meerkat)(?{14}newt)(?{15}ostrich)(?{16}penguin)(?{17}quail)(?{18}racoon)(?{19}snail)(?{20}turtle)(?{21}uakari)(?{22}vulture)(?{23}walrus)(?{24}xysticus)(?{25}yak)(?{26}zebra)
        • SEARCH MODE = Regular Expression
        • REPLACE ALL

        If you want to do more words that, understand that there are limits to the number of characters allowed in search/replace operations: if it’s more than a few hundred characters, I don’t recommend it (though it can technically go around 2000, IIRC). But for large numbers of words, even if it technically fits, it’s unweildy (even the 26 words, I used multiple regex and the Column Editor in Notepad++ to generate the regex FIND and REPLACE, because doing all the parenthesis and numbering is not something I’d want to do by hand). Thus, I highly recommend using the PythonScript plugin and a translation script, like the one I shared here – it shows translating from English into another language, but it could be used for any translation table of A,B,C into X,Y,Z. You just add more entries to the translation map if you want more pairs. (That post has instructions in it, but we now also have a FAQ which was derived from those instructions, and might be more up-to-date.)

        (thank you to wikijunior:fruit alphabet and animal alphabet for the word lists)

        1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by guy038

          Hello, @neeraj10786 and All,

          You can, indeed, search and replace multiple words, in one go, using the Regular expression search mode

          You must use the below syntax for, both, the search of these exact words and for the replace fields

          • FIND \b(?-i:(Word_1)|(Word_2)|(Word_3)|.........|(Word_n))\b

          • REPLACE (?{1}New_1)(?{2}New_2)(?{3}New_3).........(?{n}New_n)

          If you prefer an insensitive search of each word ( so, whatever the case ), simply change the beginning of the search regex to \b(?i:

          Unlike in the @peterjones’s post, I supposed that you intend to search for true words and not strings which may be embedded in bigger expressions. However the syntax are quite similar !


          One example :

          Giving this INPUT text :

          --- Word_1 --- Word_2 --- Word_3 --- Word_4 --- Word_5 --- Word_6 --- Word_7 --- Word_8 --- Word_9 --- Word_10 --- Word_11 --- Word_12 ---
          
          • Open the Replace dialog ( Ctrl+ H )

          • Uncheck all the box options

          • FIND \b(?-i:(Word_1)|(Word_2)|(Word_3)|(Word_4)|(Word_5)|(Word_6)|(Word_7)|(Word_8)|(Word_9)|(Word_10)|(Word_11)|(Word_12))\b

          • REPLACE (?{1}New_1)(?{2}New_2)(?{3}New_3)(?{4}New_4)(?{5}New_5)(?{6}New_6)(?{7}New_7)(?{8}New_8)(?{9}New_9)(?{10}New_10)(?{11}New_11)(?{12}New_12)

          • If necessary, check the Wrap around OR the In selection option

          • Click, once only, on the Replace All button

          You should get this OUTPUT text, below :

          --- New_1 --- New_2 --- New_3 --- New_4 --- New_5 --- New_6 --- New_7 --- New_8 --- New_9 --- New_10 --- New_11 --- New_12 ---
          

          Simple, isn’t !

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 1
          • CoisesC
            Coises @neeraj10786
            last edited by

            @neeraj10786:

            While I don’t use it myself (and so can’t give detailed advice), it seems like the MultiReplace plugin by @Thomas-Knoefel would be easier to use than built-in methods. If this is a single-time problem, then the built-in methods others have given make sense; but if it is something you’ll need to do repeatedly, I’d check out that plugin.

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