fixes #346: validate strings passed to the RegExp constructor

Fixes #346.