2016-12-06 93 views
1

我试图取代所有的逗号的字符串,在记事本中引号之间++。用正则表达式替换引号所有逗号记事本+

我几乎regex to remove comma between double quotes notepad++到了那里,但并不完全。现在它只是取代第一个逗号。

总结这篇文章它使用查找内容:("[^",]+),([^"]+")替换:\1\2(我改成\1~\2

是否有正则表达式办法赶上引号之间的逗号的所有实例?

编辑:添加了几个有代表性的字符串:

1,G 32,170696,01/06/2015,Jun-17,"M12 X 1,50 - 4H GO SRG",P U7,,,,SRG ,"G 32_170696_06-2017_M12 X 1,50 - 4H GO SRG_P U7.pdf" 
3,13247,163090,01/11/2015,Nov-17,"PG 0,251 to 0,500 inch",P U7,,,,,"13247_163090_11-2017_PPG 0,251 to 0,500 inch_P U7.pdf" 
9,PI 1496,182411,01/04/2015,Apr-17,"6,000 - 6,018mm GO-NOGO PPG",,,,,PPG,"PI 1496_182411_04-2017_6,000 - 6,018mm GO-NOGO PPG.pdf" 
+0

你只需要点击*,直到没有匹配的所有*数次更换。 –

+0

@WiktorStribiżew:如果你这样做,你也将替换引号外的逗号。 –

+0

您应该为您的问题添加一个有代表性的示例字符串。也可以尝试格式化你的问题好,请参阅:http://stackoverflow.com/editing-help –

回答

1

您可以使用这一模式做一通:

(?:\G(?!^)|([^"]*(?:"[^,"]*"[^"]*)*"))[^",]*\K,([^",]*+(?:"(?1)|$))? 

以此替代:~\2

demo

细节:

(?: 
    \G(?!^) # contiguous to a previous match 
    | # OR 
    ([^"]*(?:"[^,"]*"[^"]*)*") # capture group 1: first match 
           # reach the first quoted part with commas 
) 
[^",]* \K , #"# 
(# capture group 2: succeeds after the last comma 
    [^",]*+ #"# 
    (?: 
     " (?1) #"# reach the next quoted part with commas 
       # (using the capture group 1 subpattern) 
     | # OR 
     $ # end of the string: (this set a default behavior: when 
      # the closing quote is missing) 
    ) 
)? 
+0

哇,正则表达式的不错位。测试,测试,测试|:它似乎去掉后,最后逗号“ 123虽然至少对我,我挣扎着跟随它一点,所以没有设法解决它自己,我对这个数据进行测试” ” 456789, “一,二” 246 | “测试,测试,测试”,456789,一个 Futile32