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:
resultString = Regex.Replace(subjectString, "(?<!,|^)\"(?!,|$)", "");
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.Multiline
as the third parameter.
1
solved Regex expression in C# [closed]