• Login
Community
  • Login

Increment all numbers between brackets in a text

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 375 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.
  • 9
    9ferkus9
    last edited by May 4, 2021, 8:50 PM

    Hello,

    I have a txt and I want to increment it all the number between brackets [] by a certain amount (there are other numbers in the txt but are not between brackets)

    If I have this txt:

    blabla 3 blabla 6 bla[5]
    blabla3 4bwebfhwefjwe[2]
    blabla1blabla[8]

    I would like to obtain this (adding 2500):

    blabla 3 blabla 6 bla[2505]
    blabla3 4bwebfhwefjwe[2502]
    blabla1blabla[2508]

    Thank you in advance

    A 1 Reply Last reply May 4, 2021, 9:03 PM Reply Quote 0
    • A
      Alan Kilborn @9ferkus9
      last edited by Alan Kilborn May 4, 2021, 9:04 PM May 4, 2021, 9:03 PM

      @9ferkus9

      Thank you for the well-formulated problem statement.
      Unfortunately, this isn’t a task that Notepad++ can do without some outside help.
      The PythonScript plugin could be used to do such a thing with the following code:

      def change(m): return str(int(m.group(1)) + 2500)
      editor.rereplace(r'(?<=\\[)(\d+)(?=\\])', change);
      
      1 Reply Last reply Reply Quote 4
      • R
        Robin Cruise
        last edited by May 11, 2021, 6:44 AM

        @Alan-Kilborn can you tell me what does ?<= do ?

        A 1 Reply Last reply May 11, 2021, 11:21 AM Reply Quote 0
        • A
          Alan Kilborn @Robin Cruise
          last edited by May 11, 2021, 11:21 AM

          @Robin-Cruise said in Increment all numbers between brackets in a text:

          can you tell me what does ?<= do ?

          If you look HERE you will see it is a “lookbehind” assertion:

          aa0dd4f5-a842-4c94-a221-6d8b516911d6-image.png

          Thus, it is something that has to come before the match, but isn’t part of the match itself.

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