Add support for regex patterns

Regex patterns can contain unbalanced nesting characters, and hence
swallow up much of a file. Add support for Perl, Ruby and Javascript.

Also remove unnecessary character classes.