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.