Recognizing intermediate regular expression nonterminals and excluding them