Community
    • Login

    Finding numbers and batch perform arithmetics in text?

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 594 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.
    • Ciprian PopaC Offline
      Ciprian Popa
      last edited by Ciprian Popa

      Hi,
      This is the first time address to forum, but after checking I couldn’t find a similar topic, so I start this one with the formulation of the problem:
      I am trying to edit a file (in fact many) that has numbers like in the example format below:
      “1. Introduction/211,Black,notBold,notItalic,open,FitPage
      2. Amino Acid Nitrogen in Sediments/211,Black,notBold,notItalic,open,FitPage
      3. Bulk Characterization of Sediments: C/N/213,Black,notBold,notItalic,open,FitPage
      4. Isotopes and Diagenetic Fractionation/214,Black,notBold,notItalic,open,FitPage
      5. Molecular-Level Isotope Analyses/216,Black,notBold,notItalic,open,FitPage
      References/219,Black,notBold,notItalic,open,FitPage”
      Each “/###” represents a number (page number in a pdf in this example) that needs to be offset by a certain amount. Is there any implemented function that can do that in batch?
      I.e. say /001 + 12 = /013, /009 +12 = /021 etc.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Ciprian Popa
        last edited by

        @ciprian-popa said in Finding numbers and batch perform arithmetics in text?:

        Is there any implemented function that can do that in batch?

        Not natively with just Notepad++ itself.
        However, you could do it with a scripting plugin such as PythonScript.
        From the docs is a hint at doing it:

        b279506d-1bfe-4964-9876-81a3c79cf976-image.png

        The rereplace function is called with the regular expression to search for and the function to be called to replace matches.

        So maybe for your case it would look like this:

        def add_12(m):
            new_page = int(m.group(1)) + 12
            return '/{:03}'.format(new_page)
        
        editor.rereplace('/([0-9]{3})', add_12)
        
        Ciprian PopaC 1 Reply Last reply Reply Quote 4
        • Ciprian PopaC Offline
          Ciprian Popa @Alan Kilborn
          last edited by Ciprian Popa

          @alan-kilborn Hi Alan,
          Thank you for that piece of code!

          1 Reply Last reply Reply Quote 1

          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