Skip to main content
Regexflux

Blank Lines

beginner

Matches empty or whitespace-only lines.

whitespaceblanklinescleanup

Pattern

/^\s*$/gm

Try It

0 of 6 strings matched

Explanation

Matches lines that are empty or contain only whitespace characters. With the multiline flag, ^ and $ match at line boundaries.

Test Strings

Matching

Non-matching

  • has content
  • a
  • 0

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /^\s*$/gm;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

Consecutive blank lines

(^\s*$\n){2,}

Matches 2+ consecutive blank lines

Related Patterns