fork download
  1. import java.util.regex.Pattern;
  2. import java.util.regex.Matcher;
  3. class Module1{
  4. public static void main(String[] asd){
  5. String sourcestring = "\"root\",test1,1111,\"22,22\",,fdsa";
  6. Pattern re = Pattern.compile("(?:^|,)\"?((?<=\")[^\"]*|[^,\"]*)\"?(?=,|$)",Pattern.CASE_INSENSITIVE);
  7. Matcher m = re.matcher(sourcestring);
  8. int mIdx = 0;
  9. while (m.find()){
  10. for( int groupIdx = 1; groupIdx < m.groupCount()+1; groupIdx++ ){
  11. System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
  12. }
  13. mIdx++;
  14. }
  15. }
  16. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
[0][1] = root
[1][1] = test1
[2][1] = 1111
[3][1] = 22,22
[4][1] = 
[5][1] = fdsa