improved validation of regular expressions