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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -