Regex for Whitespace Only
Matches strings that contain only whitespace characters (spaces, tabs, newlines). Useful for empty input detection.
Pattern
/^\s+$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| \s+ | One or more whitespace characters |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| Match | |
| Match | |
| hello | No match |
| No match |
Common Use Cases
- Empty input validation
- Trimming detection
- Form field checking
Variations
^\s*$Allows empty string too
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester