Community
    • Login

    Finding numbers and batch perform arithmetics in text?

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 318 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.
    • Ciprian PopaC
      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
        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
          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors