Increment all numbers between brackets in a text
-
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
-
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); -
@Alan-Kilborn can you tell me what does
?<=do ? -
@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:

Thus, it is something that has to come before the match, but isn’t part of the match itself.
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