Text Processingflags: gm
Whitespace-Only Line
Matches lines containing only whitespace (or empty lines).
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^\s*$ (flags: gm)Raw 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 patterns
Trailing Whitespace (Per Line)
Text ProcessingMatch trailing spaces and tabs at the end of each line — the regex linters use to flag dirty whitespace.
Whitespace Trim (Leading & Trailing)
Text ProcessingMatch leading and/or trailing whitespace on a string — the regex equivalent of .trim().
Single-Line Comment (// or #)
Text ProcessingMatch single-line comments using either the `//` (C-family) or `#` (shell, Python, Ruby, YAML) marker.
C-Style Block Comment
Text ProcessingMatch C-style /* ... */ block comments across multiple lines.
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.