13

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.

14wml
  • 243

1 Answers1

20

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.

Kusalananda
  • 333,661
  • 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
  • 2
    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
  • 2
    Note that POSIX requires [[:space:]] to be a superset of [[:blank:]] (in any locale). http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html – Stéphane Chazelas Mar 20 '17 at 16:37
  • See also: https://www.mail-archive.com/austin-group-l@opengroup.org/msg02479.html – Stéphane Chazelas Jun 10 '20 at 08:53