import java.util.regex.*; Pattern fieldRegex = Pattern.compile( "\\G(?:^|,) \n"+ "(?: \n"+ " # Either a double-quoted field ... \n"+ " \" # field's opening quote \n"+ " ( (?: [^\"]++ | \"\" )*+ ) \n"+ " \" # field's closing quote \n"+ " # ... or ... \n"+ " | \n"+ " # ... some non-quote/non-comma text ... \n"+ " ( [^\",]* ) \n"+ " ) \n", Pattern.COMMENTS); Pattern quotesRegex = Pattern.compile("\"\""); // Given the string in 'line', find all the fields . . . Matcher m = fieldRegex.matcher(line); while (m.find()) { String field; if (m.group(1) != null) { field = quotesRegex.matcher(m.group(1)).replaceAll("\""); } else { field = m.group(2); } // We can now work with the field . . . System.out.println("[" + field + "]"); } ----------------------------------------------------------------------------- Copyright 1997-2025 Jeffrey Friedl