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.

1 Answer 1

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.

5
  • 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. Commented Mar 20, 2017 at 16:23
  • 1
    @StéphaneChazelas Is \r a vertical spacing character? Commented Mar 20, 2017 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. Commented Mar 20, 2017 at 16:35
  • 2
    Note that POSIX requires [[:space:]] to be a superset of [[:blank:]] (in any locale). pubs.opengroup.org/onlinepubs/9699919799/basedefs/… Commented Mar 20, 2017 at 16:37
  • See also: mail-archive.com/[email protected]/msg02479.html Commented Jun 10, 2020 at 8:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.