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

      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

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @9ferkus9
        last edited by Alan Kilborn

        @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
        • Robin CruiseR
          Robin Cruise
          last edited by

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

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Robin Cruise
            last edited by

            @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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors