How-to Guide 5 min read

How to Add Text to the Start or End of Every Line (Prefix, Suffix)

Add a prefix or suffix to every line of a list at once: bullets, quotes, commas, https:// or file extensions, using find and replace with a simple regex.

add text to beginning of every lineadd suffix to each lineadd prefix to each line onlineadd comma at end of each lineadd quotes around each line

The short answer

To add the same text to the start or end of every line, open Find and Replace, paste your lines and tick Use regex. For a prefix, find (^|\n)(?=.) and replace with $1 followed by your text. For a suffix, find (.)(\r?\n|$) and replace with $1 + your text + $2. To wrap each line, find (.+) and replace with your prefix, $1, then your suffix. The result updates as you type, and you can copy it with one click.

When you need this

Adding text to every line comes up whenever you move a list between tools:

  • Turning a plain list into bullet points (- item) or a Markdown quote (> line)
  • Wrapping values in quotes for code, CSV files or SQL
  • Adding a comma or semicolon to the end of each line
  • Adding https:// in front of a list of domains
  • Adding a file extension such as .jpg to a list of file names
  • Adding # in front of single-word tags

Doing it by hand is slow for more than a few lines and easy to get wrong. A regex replacement does every line at once.

How the patterns work

The Find and Replace tool uses JavaScript regular expressions with a few settings you control: Case sensitive, Whole word, Use regex and Replace all. Replace all is on by default and must stay on for these recipes, otherwise only the first line changes.

In this tool, ^ means the start of the whole text and $ means the end of the whole text, not the start or end of each line. That is why the patterns below also look for the line break character \n:

  • (^|\n) matches the very start of the text, or any line break.
  • (?=.) only lets the match happen if a character follows, so empty lines are skipped.
  • (.) matches one character that is not a line break.
  • (\r?\n|$) matches a line break (Windows or Unix style), or the end of the text.
  • (.+) matches a whole line's content, without the line break.

In the replacement, $1 and $2 put back whatever the first and second groups in brackets matched. That is how the line breaks are kept while new text is added around them.

Add text to the start of every line

  • Paste your lines into the text box.
  • Tick Use regex.
  • In Find, type (^|\n)(?=.)
  • In Replace with, type $1 followed by your prefix.
  • Check the result and click Copy.
  • Examples:

    Replace withBeforeAfter
    $1- apple- apple
    $1> Quoted text> Quoted text
    $1https://example.comhttps://example.com
    $1#travel#travel

    The (?=.) part makes sure empty lines are left alone, so a blank line at the end of your list does not get a stray bullet. If you do want the prefix on empty lines too, use (^|\n) on its own.

    Add text to the end of every line

  • Tick Use regex.
  • In Find, type (.)(\r?\n|$)
  • In Replace with, type $1, then your suffix, then $2.
  • For example, $1,$2 turns

    apple

    banana

    cherry

    into

    apple,

    banana,

    cherry,

    Other useful suffixes:

    Replace withBeforeAfter
    $1;$2SELECT 1SELECT 1;
    $1.jpg$2photo-01photo-01.jpg
    $1 (done)$2Call bankCall bank (done)

    The \r? part handles text copied from Windows programs, where each line ends with a hidden carriage return before the line break. Without it, the suffix could land after that hidden character. Empty lines are skipped because (.) needs at least one character.

    Wrap every line with a prefix and a suffix

    When you need both, one pattern is enough:

  • Tick Use regex.
  • In Find, type (.+)
  • In Replace with, type your prefix, then $1, then your suffix.
  • Replace withBeforeAfter
    "$1"Delhi"Delhi"
    '$1',1001'1001',
    [$1]Draft[Draft]

    This works line by line because the dot in (.+) does not match line breaks, so each line is a separate match. Empty lines have no characters and are skipped.

    If you want to turn the wrapped lines into a single comma-separated line for SQL, see turning a column into a comma-separated list.

    Troubleshooting

    Only the first line changed

    Replace all is unticked. Tick it and the change applies to every line.

    Nothing changed and the match count is 0

    Use regex is not ticked, so the tool is searching for the literal characters (^|\n). Tick Use regex.

    A dollar sign disappeared from my text

    In the replacement box, $ introduces a group reference such as $1. To insert a real dollar sign, type $$. For example, $1$$ puts a dollar sign at the start of each line. $& inserts the whole match, which can be handy for suffixes.

    Typing \n in Replace with gives a literal backslash-n

    The Replace with box inserts text exactly as typed, apart from $ references. You cannot type a new line break there, which is why these recipes capture the existing line break in a group and put it back with $1 or $2.

    Some lines have spaces at the end

    A suffix is added after the last character, including trailing spaces, so apple becomes apple ,. Remove trailing spaces first: find [ \t]+(?=\n|$) with Use regex ticked and leave Replace with empty.

    I need numbers, not the same text on every line

    Find and replace cannot count, so it cannot produce 1., 2., 3. Use a spreadsheet: put the lines in column B, numbers in column A, and join them. Or use the numbered list button in your word processor.

    Clean the list before you add text

    Prefixes and suffixes are easiest on a tidy list. Before you start:

    • Remove repeated entries with Remove Duplicate Lines.
    • Put the lines in order with Sort Text.
    • Remove line breaks copied from a PDF if a single item has been split across lines.

    For more patterns, including capture groups and whole-word matches, read find and replace with regex.

    Frequently asked questions

    How do I add text to the beginning of every line?

    Open Find and Replace, tick Use regex, type (^|\n)(?=.) in Find and $1 followed by your text in Replace with. For example, $1- turns each non-empty line into a bullet point.

    How do I add a comma at the end of every line?

    With Use regex ticked, find (.)(\r?\n|$) and replace with $1,$2. This adds a comma after the last character of every non-empty line and keeps the line breaks.

    How do I put quotes around each line?

    Tick Use regex, find (.+) and replace with "$1" for double quotes or '$1' for single quotes. The dot does not match line breaks, so each line is wrapped separately.

    Why does a dollar sign in my prefix disappear or show $1?

    In the replacement box, $ starts a reference to a captured group. To insert a literal dollar sign, type $$. For example, $1$$ adds a dollar sign at the start of each line.

    Can I number each line automatically?

    Not with find and replace, because a replacement cannot count. Paste the lines into a spreadsheet and use a numbered column, or use your word processor's numbered list feature.

    Try this tool on Lazyblink

    Put this guide into practice with our free online tool — no signup required.

    Open tool