Added extra sanity checks to regular expression parsing.