Line prefix and suffix
Add a prefix, a suffix or both to every line of a text: the {n} placeholder expands to a counter with configurable start, step and zero padding, a regular expression can restrict the edit to matching lines, and blank lines can be skipped. The result reports input lines, edited lines and numbered lines.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
The {n} placeholder expands to the counter; \n, \t and \\ escapes are supported. A \n in the prefix really breaks the line, so the output gains lines.
CounterEvery line break starts a line; prefix and suffix are optional, but not both at once.
Result
Output always uses LF line endings; a \n inside the affix adds extra lines.
Enter text plus a prefix or suffix to see the result
What this tool does
- Number list items, subtitles, scripts or code snippets in bulk: a prefix of “{n}. ” turns it into a numbered list.
- Tag every line with a fixed marker, for example an “[ERROR] ” prefix for logs or a trailing comma so the lines can be pasted into CSV or SQL.
- Edit only what matches: use a regular expression to prefix just the comment lines, blank lines or lines starting with a keyword, leaving everything else untouched.
Example
Input
苹果 香蕉 橙子
Output
1. 苹果 2. 香蕉 3. 橙子
Only the prefix field is filled with {n}. (everything else at its default: start 1, step 1, no zero padding).
Frequently asked questions
How is the counter computed?
It starts at “start” and advances by “step”, and only lines that actually receive a prefix or suffix take a number: lines filtered out by the regex and skipped blank lines do not consume one, so numbering stays continuous. Zero padding widens the number (the seventh entry becomes 007 with padding 3), and a negative start renders as -002.
How do I write the filter regex?
The “only lines matching” field takes a JavaScript regex source with no flags (case sensitive): ^# edits only lines starting with #, \d+ only lines containing digits, and “invert” restricts the edit to lines that do not match. An invalid regex fails loudly instead of silently editing every line.
Can the affix contain a line break?
Yes. Prefixes and suffixes support the \n, \t and \\ escapes; a literal \n really breaks the line, so each input line gains an extra output line and the result can have more lines than the input. “Input lines” always counts the input, while the result shows the real output. CRLF and lone CR are both treated as line breaks and the output uses LF.
What happens to blank lines and surrounding spaces?
They are kept as-is by default (and still get the prefix or suffix). “Skip blank lines” leaves lines that are empty after trimming untouched and unnumbered, while “trim each line first” removes surrounding spaces before the affix is added.
How is this different from the insert tools?
This tool only edits the two ends of a line: the start (prefix) and the end (suffix). To insert text inside a line, use the insert tool (a position counted from the start of the line) or the insert-at-end tool (a position counted backwards from the end), the latter also supports several insertion rules applied in order.
Keywords:line prefixline suffixadd line numbers