regex: Fix parsing of character classes

Fixes #18034

3 bugs fixed.