Regular Expression for Comma Based Splitting Ignoring Commas inside Quotes

后端 未结 1 1491
春和景丽
春和景丽 2021-01-24 01:53

In one of my projects I had to deal with Comma Separated files (CSV). I had to split data based on Comma , ignoring commas inside quotes (i.e. \"\") so

相关标签:
1条回答
  • 2021-01-24 02:12

    You need to use the split(java.lang.String, int) method

    Your code would then look like:

    String str = "20Y-62-27412,20Y6227412NK,BRACKET,101H,00D505060,H664374,06/25/2013,1,,";
    String[] rowData = str.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);
    
    0 讨论(0)
提交回复
热议问题