Added improvements and error checking to regex grammar