aspose file tools
The moose likes Java in General and the fly likes Infinite recurssion when using Regex to extract column names from SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Infinite recurssion when using Regex to extract column names from SQL

ver sd
Greenhorn

Joined: Mar 24, 2008
Posts: 4
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);
}
}

Any input on this is helpful.
Thanks in advance.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Please don't post the same question in multiple forums. It creates duplicate conversations and thereby wastes the time of the people trying to help you. See http://faq.javaranch.com/view?CarefullyChooseOneForum

Thanks.


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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Infinite recurssion when using Regex to extract column names from SQL
 
Similar Threads
need a regular expression for extracting strings.
Regex: Infinite recurssion when extracting columns from SQL
string.replaceall() and java.util.regex.Pattern/Matcher
Regular Expression pattern search is throwing "java.lang.IllegalStateException"
How to do regex searches / matches data from external file