Regex Not Capturing Nested Parentheses in SQL Query Parsing with Java
I'm working on a personal project and I'm relatively new to this, so bear with me... I'm currently working on a Java application that needs to parse SQL queries and extract values from nested parentheses. My regex pattern is not capturing the nested structures properly. For example, given the SQL string `SELECT name FROM users WHERE (age > 30 AND (city = 'New York' OR city = 'Los Angeles'))`, I want to extract everything within the outer parentheses. Here's the regex pattern I've been using: ```java String regex = "\(([^()]*|(?R))*\)"; ``` However, I'm working with the behavior `java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 17` when I try to compile it. I've also tried simplifying the regex but it doesn't capture the nested parentheses correctly. I've verified that I'm using Java 11 and the regex engine does not support recursion as in PHP or Perl. Is there a way to write a regex pattern that can handle this nested structure in Java? Alternatively, should I consider a different approach rather than regex for parsing SQL queries? Any insights or suggestions would be greatly appreciated. My development environment is Windows. Has anyone else encountered this? I'm working on a application that needs to handle this.