validate and clean function for RegexParser