7

On this website it says:

[[:blank:]]     space and tab characters
[[:space:]]     whitespace characters

What's the difference between space and tab characters and whitespace characters? To me, they almost seem the same.

12

The [[:space:]] class is a superset of [[:blank:]] which additionally (apart from the space and tab of [[:blank:]]) includes

  • the newline character (\n, line feed on Unix, ASCII code 10),
  • vertical tab (\v, ASCII code 11),
  • form feed (\f, ASCII code 12), and
  • carriage return (\r, ASCII code 13).

... in the POSIX locale, that is. Other locales may have additional space characters.

  • IOW, [[:blank:]] is horizontal spacing characters only while [[:space:]] contains all horizontal and vertical spacing characters. See also \h vs \s in perl regular expressions. – Stéphane Chazelas Mar 20 '17 at 16:23
  • 1
    @StéphaneChazelas Is \r a vertical spacing character? – Kusalananda Mar 20 '17 at 16:25
  • 1
    Except for the space character, the [[:space:]] characters in the POSIX locale are all control characters, so the behaviour will vary with the device they are sent to. CR moves the cursor/carriage back to the start of the screen/page so on its own is not really a vertical spacing character, but it's part of the CRLF sequence that is sent to ttys for a line-break so as such can be seen as vertical spacing. – Stéphane Chazelas Mar 20 '17 at 16:35
  • 1
    Note that POSIX requires [[:space:]] to be a superset of [[:blank:]] (in any locale). pubs.opengroup.org/onlinepubs/9699919799/basedefs/… – Stéphane Chazelas Mar 20 '17 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.