Small SEO Tools

How to Remove Blank Lines While Keeping Repeated List Items

A packing list can repeat an item deliberately. To remove unwanted blank rows, keep those repeated entries and the spacing on each retained line. This procedure targets empty lines and lines containing only ordinary spaces or tabs.

Start with a list whose repeats should stay

Keep a saved copy of the original. Open Find and Replace Text and paste the following into Your text. Both occurrences of Red mug begin with two spaces. There is one empty line after the first occurrence.

  Red mug

Blue plate
  Red mug

The intended result has three items in the same order, including both copies of Red mug.

Delete only the matching blank rows

Paste this pattern directly into Find, with single backslashes and no surrounding slashes or flags.

(?<=^|\n)(?:[ \t]*\r?\n|[ \t]+$)

Leave Replace with completely empty. Turn on Use regular expression and Replace all. Leave Whole word only and Match case off. Click Replace and inspect the separate result.

  Red mug
Blue plate
  Red mug

For this exact input, expect 1 replacement, 31 characters before and 30 after. Each repeated item and its indentation remains. The one removed character is the newline ending the empty row.

Understand which rows qualify

The opening (?<=^|\n) checks for the start of the input or a position immediately after a newline. This lookbehind checks the position without consuming the preceding line. See the MDN lookbehind reference.

The first branch matches optional spaces or tabs followed by an LF or CRLF line ending. The second branch removes a final row containing spaces or tabs even when it has no ending newline. The escapes \t, \r and \n represent tab, carriage return and line feed. See the MDN character escape reference.

The pattern removes consecutive blank rows in one pass. It also preserves a final newline after a nonempty item. A row containing a nonbreaking space stays in place, since this search targets ordinary spaces and tabs. Text using bare carriage returns as line endings needs a different pattern.

Check every retained item before copying

Compare the original and result in order. Check the number of intentional repeats, the indentation on both Red mug entries, and any tabs or trailing spaces belonging to your actual items. Our draft comparison guide explains the tool options for reviewing spacing differences.

Use this on a selected list whose blank rows are unwanted. Keep paragraph separation or other meaningful empty rows outside the selection. Copy the reviewed result into its destination and check the saved version once more.