Description
The problem appears to be the shear amount of back tracking being done to accomplish the match.
If your CSV is well formed you could use a more simple regex to parse each line. Note this will only separate the quote-comma and comma delimited values from a string, so you'd need to pass each line through the .matcher with this regex and iterate over each of the matches.
regex: (?:^|,)"?((?<=")[^"]*|[^,"]*)"?(?=,|$)
Java Code Example:
Live example: http://ideone.com/NBmzrk
Sample Text
"root",test1,1111,"22,22",,fdsa
Code
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Module1{
public static void main(String[] asd){
String sourcestring = "source string to match with pattern";
Pattern re = Pattern.compile("(?:^|,)\"?((?<=\")[^\"]*|[^,\"]*)\"?(?=,|$)",Pattern.CASE_INSENSITIVE);
Matcher m = re.matcher(sourcestring);
int mIdx = 0;
while (m.find()){
for( int groupIdx = 0; groupIdx < m.groupCount()+1; groupIdx++ ){
System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
}
mIdx++;
}
}
}
Capture Group 1
[0] => root
[1] => test1
[2] => 1111
[3] => 22,22
[4] =>
[5] => fdsa