top of page

add page numbering in NotePad++

If you have a text file in NotePad++ that has markers for page breakers, but you need to add in page numbering, follow these steps:

1. Begin by numbering each line so that you can sort them in their original order. Select all, and then go to Edit . . . Column Editor.

2. Select the radio button for 'Number to Insert', and then enter '1' for the 'Initial number' and 'Increase by' fields. Check off the option for 'Leading zeros'.

3. Next run a regular expression find and replace search to move the line numbering to the end of each line:

FIND: ([0-9]{2})(.*$)


This searches for any two digit number, and then also selects all of the text to the end of the line - this is what $ is used for in regex. The backslashes followed by numbers reference each regex search in parentheses in the FIND search. Putting them in reverse numerical order will flip the original text order.

4. Now sort all of the lines so the markers at the beginning of each line are grouped together. Go to TextFX . . . TextFX Tools . . . 'Sort lines case insensitive (at column)' with 'Sort ascending' selected.

5. Now just select the lines beginning with the PAGE marker and repeat step 2. To select the lines hold down ALT + SHIFT and use the down arrow key.

6. Use another regex search to move the original numbering for all lines back to the start of each line:

FIND: (^.*)([0-9]{2})


. . . the caret '^' is used in regular expression language to find the beginning of a line.

7. Relocate the numbers before each PAGE marker:

FIND: ([0-9]{1})(PAGE)


8. Resort the lines:

9. Finally simply remove the line numbers:

FIND: \r\n[0-9]{2}



bottom of page