![正则表达式在两个字符串之间找到逗号](https://linux22.com/image/1581275/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%9C%A8%E4%B8%A4%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B9%8B%E9%97%B4%E6%89%BE%E5%88%B0%E9%80%97%E5%8F%B7.png)
我正在尝试从文本文件中的某个位置删除逗号。输入如下:
Y=6","~2807-1 Q12m. 任何骨头中的板、螺丝、杆或针 - 否"
我只想删除“Y=6”、“”和结尾双引号之间的逗号。如果我使用
(?<=Y=\d“,”)。*(?=“)
我可以隔离它们之间的部分,但却无法弄清楚如何只得到逗号。
答案1
- 寻找:
(?:Y=\d","|\G)[^,"]*\K,
- 代替:
NOTHING
解释:
(?: # start non capture group
Y=\d # literally Y= followed by 1 digit. You may want to use \d+ for 1 or more digits
"," # literally ","
| # OR
\G # restart form last match position
) # end group
[^,"]* # 0 or more any character that is not comma or double quote
\K # forget all we have seen until this position
, # a comma