<p>currently I have the following code:</p>

<pre><code>String select = qry.substring("select ".length(),qry2.indexOf(" from "));
String[] attrs = select.split(",");
</code></pre>

<p>which works for the most parts but fails if given the following:</p>

<pre><code>qry = "select a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy') from tbl_a";
</code></pre>

<p>what I'm looking for is the regex to feed to String.split() which will hande that situation, and for that matter any other special cases you might be able to think of that I'm missing.</p>

```
```
[^,]+\([^\)]+\)|[^,]+,
```
```
Should do it nicely provided you always add a final ',' to your select string:
```
```
a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy'),f,gg,dr(tt,t,),fff
```
```
would fail to split the last 'fff' attributes, but:
```
```
a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy'),f,gg,dr(tt,t,),fff,
```
```
would captures it. So a little pre-processing would smooth things out.
Caveat
: this does not take into account expression within expression
```
```
EXP(arg1, EXP2(ARG11,ARG22), ARG2)
```
```
Tell me if that can happen in the queries you have to process.
Caveat bis
: since this needs a true regexp and not a simple separator expected by split(), you must use a Matcher, based on the pattern
```
[^,]+\([^\)]+\)|[^,]),
```
, and iterate on Matcher.find() to fill the array of attributes
```
attrs
```
.
In short, with split() function, there is no single simple separator that might do the trick.