Regex & Text

Regex Whitespace

Choose a whitespace token that matches the actual input: all whitespace, horizontal spacing, a specific newline convention, or only surrounding whitespace.

Published

Choose by intent

Whitespace matcher matrix

Start from what must match. Each choice loads a real pattern and the same mixed whitespace sample into Regex Tester.

Selected preset

Match any whitespace

The whitespace class includes spaces, tabs and line breaks.

\s+

Expected result: Highlights every run of whitespace in the sample.

Choose precisely

What changes the match

\\s includes more than spaces

It also includes tabs and line terminators.

[ \\t] avoids line breaks

Use the explicit class for horizontal spacing only.

\\r?\\n handles CRLF and LF

The carriage return is optional; the newline is required.

m changes anchors

Use multiline mode when trimming every line independently.

Practice with the full tool

Test your whitespace pattern

Use your own text to verify spaces, tabs, line endings and surrounding whitespace.

Continue in Regex Tester →