Could anyone help me to assemble a pattern that matches an arbitrary sequence of spaces and tabs?
Use \t to match a tab character (ASCII 0x09), \r for carriage return (0x0D) and \n for line feed (0x0A).
Most characters, including all letters ( a-z and A-Z ) and digits ( 0-9 ), match itself. For example, the regex x matches substring "x" ; z matches "z" ; and 9 matches "9" . Non-alphanumeric characters without special meaning in regex also matches itself. For example, = matches "=" ; @ matches "@" .
The \D metacharacter matches non-digit characters.
\s stands for “whitespace character”. Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a carriage return, a line feed, or a form feed.
[ \t]+
will match arbitrary sequences (e.g., spaces followed by tabs followed by more spaces ...).
\s+
should capture all whitespace, including spaces, tabs, carriage returns, and some weird whitespace characters. Use \s*
if you want it to be optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With