Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex to remove comma between double quotes notepad++

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"

and I need this:

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

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.

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

like image 835
mrki Avatar asked Apr 21 '14 20:04

mrki


People also ask

How do you remove commas in regex?

To remove all commas from a string, call the replace() method, passing it a regular expression to match all commas as the first parameter and an empty string as the second parameter. The replace method will return a new string with all of the commas removed.

How do I remove a comma from notepad?

If you find any unnecessary commas in data then you can get them removed, owing to various functions, like TRIM, SUBSTITUTE, FIND, LEN, REPLACE or you can use FIND & REPLACE (CTRL + H). You can choose from several methods to remove them.

How do I remove double quotes in notepad?

The easiest way to do this is to highlight one of the quotes, then select Search, then Replace. You will see the Find What field is already filled in with the quote you selected. I suggest have Search mode set to normal. Make sure the Replace With field is empty.

How do you match double quotes in regex?

Firstly, double quote character is nothing special in regex - it's just another character, so it doesn't need escaping from the perspective of regex. However, because Java uses double quotes to delimit String constants, if you want to create a string in Java with a double quote in it, you must escape them.


1 Answers

Try the following

import re

print re.sub(',(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$)',"",string)

This will remove comma between quotes

like image 178
Nithin Avatar answered Sep 21 '22 17:09

Nithin