Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Infinite recurssion when using Regex to extract column names from SQL  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
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( 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 =;

Any input on this is helpful.
Thanks in advance.
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
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

It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!