8

I've been playing around with rx lately, and I just noticed there are (at least) 3 different ways of indicating whitespaces in regular expressions.

  1. [:blank:]
  2. [:space:]
  3. \s-

What are the differences between each of them? Does it depend on the major-mode?

Malabarba
  • 22,878
  • 6
  • 78
  • 163
  • 3
    [***What does Emacs say?***](https://www.gnu.org/software/emacs/manual/html_node/elisp/Char-Classes.html) ([`[:space:]` and `\s-`](https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Class-Table.html#Syntax-Class-Table) are the same.) `C-h i`, Elisp manual, `C-s [:space]`. – Drew Nov 15 '14 at 15:14
  • "Playing around" `;)` – Sean Allred Nov 15 '14 at 22:37

1 Answers1

6

The [:blank:] character class matches only the SPC and TAB characters. The other two match whitespace based on the active syntax table.

There does not seem to be a difference between [:space:] and \s-. The latter is an instance of the general \scode pattern for matching based on a syntax class.

glucas
  • 20,175
  • 1
  • 51
  • 83
  • 1
    Just did a quick test modifying the syntax table in a buffer to make additional characters whitespace. Testing with `regexp-builder` I can confirm that both `[:space:]` and `\s-` match the additional characters as spaces. – glucas Nov 15 '14 at 14:48