Java regex problem in matcher.find()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vmysore
    New Member
    • Mar 2008
    • 1

    Java regex problem in matcher.find()

    I am trying to get all the columns selected within a SQL query (including the sub selects). When the code hits matcher.find(). i get the following exception:

    Exception in thread "main" java.lang.Stack OverflowError
    at java.util.regex .Pattern$Branch .match(Pattern. java:4530)
    at java.util.regex .Pattern$GroupH ead.match(Patte rn.java:4570)

    I am not sure where in the regex is causing the inifinite loop.
    Can anyone shed light on this?


    String regex = "^select(([^\\(]|\\([^\\(]+\\))*)from";
    Pattern pattern = Pattern.compile (regex, Pattern.CASE_IN SENSITIVE | Pattern.DOTALL | Pattern.MULTILI NE);
    Matcher matcher = pattern.matcher (sql);
    if (matcher.find() ) {
    // Get all groups for this match
    for (int i = 0; i <= matcher.groupCo unt(); i++) {
    String groupStr = matcher.group(i );
    }
    }
    Last edited by vmysore; Mar 17 '08, 08:26 PM. Reason: appropriate title
Working...