• Login
Community
  • Login

mass replace diffrent text in file

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 4 Posters 452 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.
  • C
    Clyde Parker
    last edited by Feb 2, 2021, 7:32 PM

    i have a large text file where i would like to replace an extension with regex, help me

    example

    Z site:com
    Y site:fr
    X site:uk
    

    to:

    Z site:pl
    Y site:pl
    X site:pl
    
    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Terry R Feb 2, 2021, 7:41 PM Feb 2, 2021, 7:40 PM

      @Clyde-Parker said in mass replace diffrent text in file:

      where i would like to replace an extension with regex,

      Using the Replace function we have
      Find What:(?-s)([^:]+).+$
      Replace With:\1:pl
      As this is a regex the “search mode” needs to be regular expression. Wrap around can be ticked.

      You can either hit the “Replace button” to see each change, or the Replace All button to do the entire file in 1 go.

      Terry

      PS this assumes there is ONLY 1 : in the line, immediately before the “extension” you wish to change. As you haven’t really shown us “real” data this is assumed.

      A 1 Reply Last reply Feb 2, 2021, 7:58 PM Reply Quote 4
      • T
        Terry R
        last edited by Feb 2, 2021, 7:57 PM

        @Terry-R said in mass replace diffrent text in file:

        PS this assumes there is ONLY 1 : in the line

        As a matter of interest the easy way to determine if ANY line has more than 1 : is to run a regex using the “Find” function and using the “Count” button.
        So the regex could be (my version, there are many ways to do this)
        Find What:(?-s)^([^:]+)*:([^:]+)*:

        Again as a regex the search mode must be “regular expression” and you should either have the cursor at top of file, or make sure “wrap around” is ticked so that it can check the entire content of the file. After clicking the “Count” button the bottom of the “Find” window will show you:
        “Count: xx matches from caret to end of file” (my setting was not “wrap around”) or “in entire file” and xx is the number 0 or more.

        Terry

        1 Reply Last reply Reply Quote 1
        • A
          Alan Kilborn @Terry R
          last edited by Alan Kilborn Feb 2, 2021, 7:59 PM Feb 2, 2021, 7:58 PM

          @Terry-R

          Maybe the OP wants to replace only com, fr, and uk after a :, which is easy to do, but why bother unless the OP clarifies the need.

          Plus OP is starting to become a “regex taker” and should be requested to show what he’s tried and failed with, before receiving additional help.

          1 Reply Last reply Reply Quote 1
          • G
            guy038
            last edited by Feb 2, 2021, 7:59 PM

            Hi, @clyde-parker, @terry-r and All,

            Again, fairly easy :

            Like @terry-r, I assume just one : per line, followed with a country identifier, ending the current line

            SEARCH (?<=:)\l+

            REPLACE pl

            The search regex tries to match the greatest range, non empty, of lowercase letters, which is immediately preceded with a colon :

            You must use the Replace All button, exclusively, if your N++ version is prior the v7.9.1 version. Else, the Replace button can be used as well ;-))

            Best regards,

            guy038

            1 Reply Last reply Reply Quote 2
            • T
              Terry R
              last edited by Feb 2, 2021, 8:00 PM

              @Alan-Kilborn said in mass replace diffrent text in file:

              Maybe the OP wants to replace only com, fr, and uk after a :

              True, we often deal in ambiguities. The OP will need to expand on request if current solution does NOT meet his needs.

              Terry

              1 Reply Last reply Reply Quote 1
              • G
                guy038
                last edited by guy038 Feb 2, 2021, 9:30 PM Feb 2, 2021, 8:14 PM

                Hi, @terry-r and All,

                To count all the lines which contain, at least, two : signs, this regex should be enough :

                SEARCH (?-s):.*:

                Indeed, we do not have to care about text before the first colon and text after the second colon ;-))

                And, if you click on the Find Next button it matches all the range of characters between these two colons, included !

                Best Regards

                guy038

                1 Reply Last reply Reply Quote 2
                • C
                  Clyde Parker
                  last edited by Feb 2, 2021, 9:55 PM

                  thanks everyone for your help, i’ve got how to make this work

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