I have a CSV file like below
COL1,COL2,COL3,COL4
3920,10163,"ST. PAUL, MN",TWIN CITIES
I want to read the file and split them outside double quotes WITHOUT using any external libraries. For example in the above CSV, we need to split them into 4 parts as
1. 3920
2. 10163
3. ST. PAUL, MN
4. TWIN CITIES
i tried using regex with folliwing code but never worked. I want to make this work using Groovy code. I tried different solutions given in Java. But couldnt achieve the solution.
NOTE : I dont want to use any external grails/Jars to make this work.
def staticCSV = new File(staticMapping.csv")
staticCSV.eachLine {line->
def parts = line.split(",(?=(?:[^\"]\"[^\"]\")[^\"]\${1})")
parts.each {
println "${it}"
}
}