Description
Given a comma-separated record where
- each field may be enclosed by a pair of double quotes,
- fields are separated by commas, and
- any character escaped by a backslash is treated literally.
In the following, we want to extract the 3rd field.
|
| Raw Input
|
| Desired Output
| 0,1\,2,"3,4,5\",6,7",8,9
aa,"bb,cc\",dd",ee\,ff,"gg",hh,ii,jj
AA,BB,CC,DD,EE
|
| "3,4,5\",6,7"
ee\,ff
CC
|
|
Script and Comments
Script1 [ 1] s/^((([^",\]|\\.)*|"([^"\]|\\.)*"),){2}(([^",\]|\\.)*|"([^"\]|\\.)*")(,.*|$)/\5/
| |
|