• Login
Community
  • Login

Range Replace - Regular Expression

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 4 Posters 1.4k 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.
  • B
    bitsense meow2x
    last edited by May 18, 2020, 10:00 PM

    Hi Team. I need help on what regular expression I can use to replace the following in range?

    For example, I want to replace the 001 value to 001, 002, 003, to 150 values.

    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com
    eapp001.auto.testing.com

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Terry R May 18, 2020, 10:26 PM May 18, 2020, 10:25 PM

      @bitsense-meow2x said in Range Replace - Regular Expression:

      I want to replace the 001 value to 001, 002, 003, to 150 values

      Welcome to the NPP forum. It’s a fairly simple process.
      I presume you want an incrementing number associated with each line, replacing the “001” present in every line.

      To do this, place the cursor in the very first position on the starting line. Then whilst holding the “Alt” key and the left mouse button down scroll down this column (actually it’s immediately to left of first column). Go for the number of lines you wish the replacement numbers to appear on (you seem to suggest 150). The bottom bar on NPP shows how many lines are currently selected to help you.

      If correctly selected a long thin line is flashing in the first position (before first character of every line). Now select Edit (main menu), then Column Editor. Select the “number to insert”, then type 1 in the “initial number” field, and 1 in the “increase by” field. Also tick the box “leading zeros”. Click OK and you should now have the numbers 001, 002, 003 etc down the left side of each line.

      Now you will be using a regex (regular expression) to replace the exsisting numbers with the new numbers. So using the “Replace” function you will have:
      Find what:(?-s)(\d{3})(\w+)(\d{3})
      Replace With:\2\1
      Make sure search mode is set to “regular expression” and wrap around should also be ticked. Now click the “Replace All” button.

      If your example is a faithful representation of the actual data you should now have the replacement numbers in the correct position.

      Terry

      once incrementing numbers are added:

      001eapp001.auto.testing.com
      002eapp001.auto.testing.com
      003eapp001.auto.testing.com
      004eapp001.auto.testing.com
      005eapp001.auto.testing.com
      006eapp001.auto.testing.com
      007eapp001.auto.testing.com
      008eapp001.auto.testing.com
      009eapp001.auto.testing.com
      010eapp001.auto.testing.com
      011eapp001.auto.testing.com
      012eapp001.auto.testing.com
      013eapp001.auto.testing.com
      014eapp001.auto.testing.com
      015eapp001.auto.testing.com
      016eapp001.auto.testing.com
      017eapp001.auto.testing.com
      018eapp001.auto.testing.com
      019eapp001.auto.testing.com
      020eapp001.auto.testing.com
      021eapp001.auto.testing.com
      022eapp001.auto.testing.com
      023eapp001.auto.testing.com
      024eapp001.auto.testing.com
      025eapp001.auto.testing.com
      026eapp001.auto.testing.com
      027eapp001.auto.testing.com
      

      Once the regex is used:

      eapp001.auto.testing.com
      eapp002.auto.testing.com
      eapp003.auto.testing.com
      eapp004.auto.testing.com
      eapp005.auto.testing.com
      eapp006.auto.testing.com
      eapp007.auto.testing.com
      eapp008.auto.testing.com
      eapp009.auto.testing.com
      eapp010.auto.testing.com
      eapp011.auto.testing.com
      eapp012.auto.testing.com
      eapp013.auto.testing.com
      eapp014.auto.testing.com
      eapp015.auto.testing.com
      eapp016.auto.testing.com
      eapp017.auto.testing.com
      eapp018.auto.testing.com
      eapp019.auto.testing.com
      eapp020.auto.testing.com
      eapp021.auto.testing.com
      eapp022.auto.testing.com
      eapp023.auto.testing.com
      eapp024.auto.testing.com
      eapp025.auto.testing.com
      eapp026.auto.testing.com
      eapp027.auto.testing.com
      
      1 Reply Last reply Reply Quote 3
      • B
        bitsense meow2x
        last edited by May 18, 2020, 10:48 PM

        @Terry-R said in Range Replace - Regular Expression:

        \2\1

        It worked!! Thank you so much, this is a life saver!

        1 Reply Last reply Reply Quote 3
        • G
          guy038
          last edited by guy038 May 19, 2020, 11:39 AM May 19, 2020, 11:38 AM

          Hello, @bitsense-meow2x, @Terry-R and All,

          Even more simple : no plugin, just native N++ features !

          • Create a rectangular selection that includes the numbers

          • Open the Column Editor ( ALT + C )

          • Choose the Number to insert option

          Here we are !

          Best regards

          guy038

          A 1 Reply Last reply May 19, 2020, 11:51 AM Reply Quote 2
          • A
            Alan Kilborn @guy038
            last edited by Alan Kilborn May 19, 2020, 11:52 AM May 19, 2020, 11:51 AM

            @guy038

            Good technique.

            Slight mod:
            The OP mentioned the top end being 150, so the selection should probably really be:

            412f6922-e2a5-4098-912a-5a015e2ac03e-image.png

            But, if the OP couldn’t extrapolate your solution to that, there’s a bigger problem. :-)

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