Whitespace in Regex: Spaces, Tabs, Newlines
Match whitespace precisely with regex: \s, \t, \n, \r, \f, \v and Unicode space categories. Patterns for trimming, collapsing, and splitting on whitespace.
Published:
Tags: text, developer-tools, programming
Whitespace in Regular Expressions: \s, \t, \n, and the x Flag Regular expressions treat whitespace as first-class content — but which whitespace? The answer depends on which character class you use. is broad and sometimes too broad. is precise. means different things in different regex flavors. And the flag (verbose mode) lets you use literal whitespace inside a regex without it being interpreted as a match pattern. This guide covers every whitespace-related regex tool you need for text processing. --- The Character Class is the most common whitespace pattern. It matches: | Character | Unicode | Name | |-----------|---------|------| | | U+0020 | Space | | | U+0009 | Horizontal Tab | | | U+000A | Line Feed | | | U+000D | Carriage Return | | | U+000C | Form Feed | | | U+000B | Vertical Tab…
All articles · theproductguy.in