2016-12-06 66 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

相關問題