Blank Lines
beginnerMatches empty or whitespace-only lines.
whitespaceblanklinescleanup
Pattern
/^\s*$/gmTry 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
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full 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