Regular expression allow you to use Bracket Expression to represent the set of collating elements. The syntax for Bracket Expression
is [...]
, where you can place in ...
any of collating elements, collating symbols, equivalence classes, character classes, or range expressions.
The one you use alpha
is a character class name, made by place class name between [:
and :]
. So, you have used the character class expression [:alpha:]
in between Bracket Expression
[[:alpha:]]
.
The character class expression is not the same as range expression [a-zA-Z]
in some locales. Here's the best example you can see:
$ LC_ALL=en_US.utf8 bash -c 'case b in [A-Z]) echo yes; esac'
yes
while using character class gave you nothing:
$ LC_ALL=en_US.utf8 bash -c 'case b in [[:upper:]]) echo yes; esac'
The caret ^
, if place at the beginning of Bracket Expression
will negate the match of expression. [^[:alpha:]]
will match any characters, which don't belong to [:alpha:]
characters class:
$ case 1 in [^[:alpha:]]) echo yes;; esac
yes