How to split a string by comma ignoring comma in double quotes How to split a string by comma ignoring comma in double quotes powershell powershell

How to split a string by comma ignoring comma in double quotes


[string].split() method doesn't accept regex on split but just [char[]] or [string[]].

You can try like this:

 $line -split ',(?=(?:[^"]|"[^"]*")*$)' 

powershell -split accept regex for splitting text

Using .net you can do it like this:

[regex]::Split( $line , ',(?=(?:[^"]|"[^"]*")*$)' )