Infinite recurssion when using Regex to extract column names from SQL
ver sd
Greenhorn
Joined: Mar 24, 2008
Posts: 4
posted
0
I am trying to get all the columns 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.StackOverflowError at java.util.regex.Pattern$Branch.match(Pattern.java: 4530) at java.util.regex.Pattern$GroupHead.match(Pattern.ja va:4570)
I am not sure where in the regex is causing the inifinite recursion. Can anyone shed light on this?
String regex = "^select(([^\\(]|\\([^\\(]+\\))*)from"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); Matcher matcher = pattern.matcher(sql); if (matcher.find()) { // Get all groups for this match for (int i = 0; i <= matcher.groupCount(); i++) { String groupStr = matcher.group(i); } }
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus