Reputation: 375
^[[:space:]]*@
I can't figure out what the [[:space:]]*
means in the above regular expression. Please help, thanks!
Upvotes: 1
Views: 153
Reputation: 211570
There are a number of ways of expressing things like "whitespace character", and this is one of them. The set [...]
allows the inclusion of things like [:space:]
to add space characters to the set.
This reads as:
^ # At the beginning of string...
[[:space:]]* # ...zero or more whitespace characters...
@ # ...followed by an at sign.
Upvotes: 0
Reputation: 5762
[:space:]
is a POSIX character class
which matches All whitespace characters, including line breaks
in the word.
In other words [:space:]
is identical to \s
(since Perl 5.18[1])
http://www.regular-expressions.info/posixbrackets.html
Before 5.18, the vertical tab (U+000B) wasn't included in \s
.
$ diff -u <( unichars -au '\s' ) <( unichars -au '[[:space:]]' ) \
&& echo 'no difference'
--- /dev/fd/63 2013-05-21 22:08:03.000000000 -0400
+++ /dev/fd/62 2013-05-21 22:08:03.000000000 -0400
@@ -1,5 +1,6 @@
---- U+00009 CHARACTER TABULATION
---- U+0000A LINE FEED (LF)
+ ---- U+0000B LINE TABULATION
---- U+0000C FORM FEED (FF)
---- U+0000D CARRIAGE RETURN (CR)
---- U+00020 SPACE
Upvotes: 9
Reputation: 46183
This is a POSIX character class, in this case a Unicode-friendly way of representing "any whitespace character".
See this page, scroll down to "POSIX Character Classes".
Upvotes: 4