正则表达式删除双引号记事本++之间的逗号 [英] regex to remove comma between double quotes notepad++

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

问题描述

我正在尝试从记事本++中的 csv 文件中删除双引号内的逗号,这就是我所拥有的:

I am trying to remove commas inside double quotes from a csv file in notepad++, this is what I have:

1070,17,2,GN3-670,"COLLAR B, M STAY","2,606.45"

我需要这个:

1070,17,2,GN3-670,"COLLAR B M STAY","2606.45"

我试图使用带有 reg exp 的记事本查找/替换选项.图案.我尝试了各种组合,但都没有成功:(该文件包含 100 万行.

I ma trying to use notepad find/replace option with a reg exp. pattern. I tried all kind of combination but didn't manage to do :( The file contains 1 million rows.

整个今天之后,我不再确定一个简单的正则表达式是否可以做?也许我应该使用脚本...python?

After whole today I am not anymore sure if a simple regex can do? Maybe I should go with a script...python?

推荐答案

mrki,这将满足您的需求(在 N++ 中测试):

mrki, this will do what you want (tested in N++):

搜索:("[^",]+),([^"]+")

替换:$1$2\1\2

这是如何工作的?第一个括号将字符串的开头(但不包括)捕获到第 1 组中.第二个括号将逗号后面的字符串末尾捕获到第 2 组中.替换用第 1 组和第 2 组的串联替换字符串第 2 组.

How does this work? The first parentheses capture the beginning of the string up to (but not including) the comma into Group 1. The second parentheses capture the end of the string after the comma into Group 2. The replacement substitutes the string with a concatenation of Group 1 and Group 2.

更详细地说:在第一个括号中,我们匹配开头的双引号,然后匹配任意数量的非逗号字符.这就是[^,]+的含义.在第二个括号中,我们将任意数量的不是双引号的字符与 [^"]+ 匹配,然后是双引号.

In more detail: in the first parentheses, we match the opening double quotes then any number of characters that are not a comma. That is the meaning of [^,]+. In the second parentheses, we match any number of characters that are not a double quote with [^"]+, then the closing double quotes .

这篇关于正则表达式删除双引号记事本++之间的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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