Community
    • Login

    Increment all numbers between brackets in a text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 649 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors