updated grammar to use regex and refactor