a full implementation of regular expression