Text Processingflags: gm
Whitespace-Only Line
Matches lines containing only whitespace (or empty lines).
Try it in RegexProPattern
regexJavaScript
/^\s*$/gmRaw source: ^\s*$
How it works
`^\s*$` anchors to a full line that contains zero or more whitespace characters and nothing else.
Examples
Input
line one
line twoMatches
Common use cases
- Whitespace cleanup
- Linters
- Blank-line detection
Related concepts
How to Match Whitespace in Regex
How-to\s matches any whitespace — space, tab, newline, and more. Use \s+ to collapse runs, ^\s*$ to detect blank lines, and \S for non-whitespace.
How to Replace Text Using Regex in JavaScript
How-toString.replace and String.replaceAll accept a regex. Use the g flag for multi-match replace, $1/$2 for capture references, and a function for complex logic.