I need a regex expression in C# which can remove any number of double quotes coming in my string, it is a csv file where after reading from StreamReader I want to replace all double quotes coming in my string. First row is header and second is data. For ex:
"E-mail","First Name","Last Name","Company"
"san@test.com","sanjay","sen","this is my "test" company"
So ideally regex should give following output :
"E-mail","First Name","Last Name","Company"
"san@test.com","sanjay","sen","this is my test company "
So double quotes removed from column "this is my "test" company" and resultant into "this is my test company"
You should try to fix the source of improperly escaped strings instead of mucking around with a regex. If you can’t do that and are desperate to get something done, one quick and dirty approach would be to remove quotes that don’t border on commas or start/end of string:
This assumes that you’re handling one CSV row at a time. If you have the entire file in a single string, then use
RegexOptions.Multilineas the third parameter.