diff --git a/compile.go b/compile.go index 91b098c..93dc54d 100644 --- a/compile.go +++ b/compile.go @@ -481,6 +481,16 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { if i >= len(re_postfix) { return nil, fmt.Errorf("Opening bracket with no closing bracket.") } + + // Check if a POSIX character class was specified ouside a bracket. This is an error. + // Eg. [:digit:] should lead to an error, telling the user that the right syntax is [[:digit:]] + if re_postfix[i] == ':' { + posixClassPresent, _ := getPOSIXClass(re_postfix[i+1:]) + if posixClassPresent { + return nil, fmt.Errorf("The syntax for POSIX character classes is [[:digit:]], not [:digit:]") + } + } + var invertMatch bool if re_postfix[i] == '^' { invertMatch = true