Replace comma between quotes in CSV with Regex

前端 未结 3 785
南旧
南旧 2021-01-20 12:16

We have for example a string like this:

\"COURSE\",247,\"28/4/2016 12:53 Europe/Brussels\",1,\"Verschil tussen merk, product en leveranciersverantwoordelijke         


        
3条回答
  •  旧巷少年郎
    2021-01-20 12:29

    First of all, you should check Understanding CSV files and their handling in ABAP article.

    For a one-time job, you can use this regex (but note that with longer strings, it may not work well, use it as a means of last resort):

    ,(?!(?:[^"]*"[^"]*")*[^"]*$)
    

    See the regex demo

    Pattern details:

    • , - a comma that...
    • (?! - is not followed with....
      • (?: -
        • [^"]* - zero or more chars other than "
        • " - a double quote
        • [^"]*" - see above
      • )* - zero or more sequences of the above grouped patterns
      • [^"]* - zero or more chars other than "
      • $ - end of string
    • ) - end of negative lookahead

提交回复
热议问题