仕様に従って二重引用符を一重引用符に置き換えるには、この単純な正規表現を使用します。この正規表現では、行の先頭または末尾、あるいはその両方に空白を使用できます。
string pattern = @"(?<!^\s*|,)""(?!,""|\s*$)";
string resultString = Regex.Replace(subjectString, pattern, "'", RegexOptions.Multiline);
これはパターンの説明です:
// (?<!^\s*|,)"(?!,"|\s*$)
//
// Options: ^ and $ match at line breaks
//
// Assert that it is impossible to match the regex below with the match ending at this position (negative lookbehind) «(?<!^\s*|,)»
// Match either the regular expression below (attempting the next alternative only if this one fails) «^\s*»
// Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
// Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s*»
// Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
// Or match regular expression number 2 below (the entire group fails if this one fails to match) «,»
// Match the character “,” literally «,»
// Match the character “"” literally «"»
// Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!,"|\s*$)»
// Match either the regular expression below (attempting the next alternative only if this one fails) «,"»
// Match the characters “,"” literally «,"»
// Or match regular expression number 2 below (the entire group fails if this one fails to match) «\s*$»
// Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s*»
// Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
// Assert position at the end of a line (at the end of the string or before a line break character) «$»