Reputation: 111
In regular expression, i know when use \s to represent a space, but, in following case, would they be different:
thanks a lot if you can explain to me.
Upvotes: 5
Views: 7101
Reputation: 2061
The \s character class matches all "whitespace characters," not just spaces. This includes tabs (\t), and if multiline matching is allowed, it includes carriage return (\r) and newline (\n). Theoretically, if your regular expression engine handles unicode, there are also unicode whitespace characters that \s can match, though your mileage may vary.
So with a string like "a\t b", you can match it with the regex /a\s+b/, in case that is useful to you.
Upvotes: 15