What is the Add Line Numbers / Remove Line Numbers?
The Add / Remove Line Numbers tool allows you to append sequential numbers to the beginning of every line in your text, or conversely strip existing numbers, prefixes, and timestamps. With customizable options for zero-padding (e.g., 001, 002), custom delimiters (e.g. 1. , 1) , or [1]: ), and starting indices, formatting lists is effortless.
Adding line numbers is common when preparing code reviews, legal depositions, poetry citations, and academic transcripts where specific row references are required. Stripping line numbers is equally vital when copying code snippets from tutorials or blogs that accidentally included numbered gutter lines.
How to Use the Add Line Numbers / Remove Line Numbers
- Paste Text: Insert your raw text into the input box.
- Choose Action: Select Add Line Numbers or Remove Line Numbers.
- Configure Style (for Adding): Choose separator (e.g., period, colon, tab) and zero-padding width.
- Copy Result: Grab your cleaned or numbered text with one click.
Formula & How It Works
Adding and stripping line numbers follows standard string mapping:
To Add Line Numbers:
lines.map((line, idx) => {
num = (idx + startNumber).toString().padStart(padLength, '0')
return num + delimiter + ' ' + line
}).join('\n')
To Remove Line Numbers:
// Strip leading digits followed by common delimiters (., ), :, -, tabs, spaces)
lines.map(line => line.replace(/^\s*\d+[:.)\]\-\s]\s*/, '')).join('\n')Worked Example: A 3-line list of tasks numbered with zero-padding (width 2) and period delimiter: 01. First Task, 02. Second Task, 03. Third Task.
Practical Worked Examples
| Mode | Original Input | Output Result |
|---|---|---|
| Add Numbers (1.) | Apple Banana | 1. Apple 2. Banana |
| Add Padded (001:) | Start Finish | 001: Start 002: Finish |
| Remove Numbers | 1. First 2. Second | First Second |
Common Everyday & Professional Use Cases
Cleaning code snippets copied from blogs with line number gutters, numbering legal contract provisions, formatting step-by-step documentation, and preparing reference citations.