How do I renumber the numbers of the following superscript in a text document? :-
Hfghh<sup>[1]</sup>. Hfgghc<sup>[1]</sup>. Fhvfh<sup>[2]</sup>. Dfyhh<sup>[3]</sup>. Xfghg<sup>[4]</sup>. Rfchh<sup>[5]</sup>. Ffhvy<sup>[6]</sup>. Xfhhb<sup>[7]</sup>. Tfhfh<sup>[8]</sup>. Igxfg<sup>[9]</sup>. Atgvvh<sup>[10]</sup>. Zfthb<sup>[11]</sup>. Phfdb<sup>[12]</sup>.
The output should be as follows:-
Hfghh<sup>[1]</sup>. Hfgghc<sup>[2]</sup>. Fhvfh<sup>[3]</sup>. Dfyhh<sup>[4]</sup>. Xfghg<sup>[5]</sup>. Rfchh<sup>[6]</sup>. Ffhvy<sup>[7]</sup>. Xfhhb<sup>[8]</sup>. Tfhfh<sup>[9]</sup>. Igxfg<sup>[10]</sup>. Atgvvh<sup>[11]</sup>. Zfthb<sup>[12]</sup>. Phfdb<sup>[13]</sup>.
That is, the numbering should start from "1" and incrementally increase by "1", without any repetition of numbers. I have been doing it one by one but that is cumbersome since there are more than a hundred of them.
I understand how to use Notepad++ but that too involves many steps to get the desired output and I am looking for something less cumbersome. The method I used with the help of Notepad++ was as follows:
<sup>\[\d+\]<\/sup>
in the "Find" field and <sup>[]</sup>
in the "Replace" field and hit "Replace All" which removes all the numbers.<sup>\[\]<\/sup>
in the "Find" field and <sup>[\r\n]</sup>
in the "Replace" field and hit "Replace All" (still with the regular expression mode selected) to put the ]</sup>
on the next line.]</sup>
and keep pressing Alt+Shift+↓ till you reach the last ]</sup>
.<sup>\[\R(\d+)
in the "Find" field and <sup>[$1
in the "Replace" field and hit, "Replace All" which puts what was on the next line as the <sup>[
on the same line as the <sup>[
.<sup>\[(\d+)\s*\]
in the "Find" field and <sup>[$1]
in the "Replace" field and hit, "Replace All" to get rid of the spaces after the numbers.That gives me (or you) the desired output (superscript numbers starting with "1" and incrementally increased by "1", without any repetition of numbers), but it is cumbersome and I want a shorter, less cumbersome process to do the same.
The answer posted at vim, is it possible to add increasing numbers next to words each time the words are repeated in a text? seems good but I don't understand the script nor how to use it.
For the benefit of future readers:-
@Toto's answer may replace other numbers as well, so I am posting another PythonScript here to match <sup>
, followed by a [
bracket and then the number sought as per the question. You can run a python script within the PythonScript plugin of Notepad++ for that.
If it is not yet installed, install it via Plugins Admin. To install the PythonScript plugin in Notepad++, navigate to Plugins > Plugins Admin. Check the box next to PythonScript and click Install. Notepad++ will restart, and after that, you can find the plugin in the Plugins menu.
Create a script (Plugins >> PythonScript >> New Script)
Copy this code and save the file (for example increment.py):
# encoding=utf-8
from Npp import *
def custom_replace_func(m):
new_text = "<sup>\[{}".format(custom_replace_func.counter)
custom_replace_func.counter += custom_replace_func.increment
return new_text
custom_replace_func.counter = 1 # starting value
custom_replace_func.increment = 1
editor.rereplace(r'<sup>\[(\d+)', custom_replace_func)
Open the file you want to modify
Run the script (Plugins >> PythonScript >> Scripts >> increment)
Then, in the result obtained after the above, put the cursor before the first <sup>
and hit Ctrl+H and in the pop-up, type <sup>.*?\[
in the "Find" field and <sup>[
in the "Replace with" field and hit “Replace all” after selecting the "Regular expression" mode to get rid of the \
after every <sup>