Finding numbers and batch perform arithmetics in text?
-
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. -
@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: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)
-
@alan-kilborn Hi Alan,
Thank you for that piece of code!