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
rereplacefunction 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!
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