我正在尝试替换记事本++中引号之间的字符串中的所有逗号。
我几乎与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 :(得分:1)
您可以使用此模式一次性完成:
(?:\G(?!^)|([^"]*(?:"[^,"]*"[^"]*)*"))[^",]*\K,([^",]*+(?:"(?1)|$))?
使用此替换:~\2
细节:
(?:
\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)
)
)?