Regular Expression Parser in Pure JS