Regular expression parser with backtracking