recursive version of regular expression engine