grammar generation regex optimistations