regex - Split line at commas, only if commas not contained between quotes -


is there way use split function in scala splits line @ commas doesn't @ commas contained within 2 double quotes?

for example, have following:

x: string = """"??", "hamburger", "ketchup, mayo, mustard", "pizza"""" 

and tried this: x.split(',') didn't work. thought removing double quotes still doesn't solve problem.

any appreciated!

edit:

here's snippet of code see how can incorporate this:

val data1 = noheader1.map { line =>   val values = line._1.split(',') //this trying change   val name = values(2).replaceall("\"", "")) 

i bit new scala , more regex, clarify how write weird regex expression in code can obtain array of comma separated words of line?

try this!

(?>"(?>\\.|[^"])*?"|(,)) 

regex101


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -