Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
    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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Infinite recurssion when using Regex to extract column names from SQL

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

We find this kind of rampant individuality very disturbing. But not this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic