Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between [:space:] and [:blank:]?

Tags:

regex

grep

bash

From the A Brief Introduction to Regular Expressions

[:blank:] matches a space or a tab.

[:space:] matches whitespace characters (space and horizontal tab).

To me both definitions are the same and I was wondering if they are really duplicates?

If they are different, what are the differences?

like image 504
Julien Grenier Avatar asked Apr 02 '13 15:04

Julien Grenier


2 Answers

For the GNU tools the following from grep.info applies:

[:blank:]

     Blank characters: space and tab.

[:space:]

     Space characters: in the 'C' locale, this is tab, newline,
     vertical tab, form feed, carriage return, and space.

You can find the section with this command:

info grep 'Regular Expressions' 'Character Classes and Bracket Expressions'
like image 187
Thor Avatar answered Sep 17 '22 14:09

Thor


A better explanation of what they each match is available here

  • http://www.regular-expressions.info/posixbrackets.html

The biggest difference is that [:space:] will also match items like new line characters

like image 24
JaredPar Avatar answered Sep 18 '22 14:09

JaredPar