用正则表达式替换CSV中引号之间的逗号 [英] Replace comma between quotes in CSV with Regex

查看:273
本文介绍了用正则表达式替换CSV中引号之间的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我们有一个像这样的字符串:

We have for example a string like this:

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

目标是替换"merk,product"之间的逗号,并保持逗号如,"和,&,",以便我们可以正确地分割文件.

The Goal is to replace the comma between "merk, product" and to keep the comma like "," and ", & ," so we can split the file correctly.

有什么建议吗?

亲切的问候

推荐答案

首先,您应该检查

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

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

请参见 regex演示

模式详细信息:

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

          这篇关于用正则表达式替换CSV中引号之间的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆