Why are there double brackets in character classes in POSIX?

On POSIX, why does a character class such as [[:digit:]]have double brackets? Do the outer and inner brackets match the same? Thanks

+4
source share
2 answers

A character class defines a character set. The statement is β€œmatch one character specified by the class”. [:digit:]is the POSIX character class, and [ ... ]is the expression in parentheses.

The designation of the POSIX class is valid only inside the expression in parentheses. For example, [:digit:]if not inside the expression in brackets, it will not be considered a class named POSIX. Most likely, in most flavors character class containing the symbols ( :, d, i, g, t) literally.

+7
source

External brackets indicate that any character is mapped. [:digit:]- POSIX character class "any digit". For example, it [[:digit:][:alpha:]]says "any number or any alphabetical character." In ASCII is [[:digit:][:alpha:]]equivalent [0-9a-zA-Z].

+5
source

All Articles