'Why I am getting "unbalanced parenthesis" error in flex

I was testing something with lexer, and wrote this regex rule:
[0-9([a-b])[c-f]] ;

According this docs, this is equivalent to:
[0-9a-f()] ;

For example, the following character classes are all equivalent:
[[:alnum:]]
[[:alpha:][:digit:]]
[[:alpha:][0-9]]
[a-zA-Z0-9]

But this is giving me error:

my_lexer.l:56: unbalanced parenthesis

Surprisingly, this rule won't give the same error!
[0-9([a-b][c-f]] ;

Can someone tell where I'm wrong.. I am using win_flex v2.6.4



Solution 1:[1]

Inside a character class, no character has special significance except \, ], and -. (But see below.) So [0-9([a-b])[c-f]] starts with the character class [0-9([a-b] (digits, letters a, and b and the symbols ( and [). The next character is an unbalanced close parenthesis , which is an error.

You may have been misled by the syntax of Posix character classes. The sequence [: is special inside a character class, but that doesn't apply to a [ not followed by a :.

As indicated in the comments, that misunderstanding is certainly related to a bug in the documentation, which I reported as issue 521.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1