且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用正则表达式替换 CSV 中引号之间的逗号

更新时间:2023-02-17 21:56:27

首先,你应该检查 了解 CSV 文件及其在 ABAP 中的处理 文章.

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):

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

查看正则表达式演示

模式详情:

  • , - 一个逗号...
  • (?! - 后面没有......
    • (?: -
      • [^"]* - 除 "
      • 之外的零个或多个字符
      • " - 双引号
      • [^"]*" - 见上
      • , - a comma that...
      • (?! - is not followed with....
        • (?: -
          • [^"]* - zero or more chars other than "
          • " - a double quote
          • [^"]*" - see above