resultString = Regex.Replace(subjectString,
@"([""'])# Match a quote, remember which one
(?: # Then...
(?!\1) # (as long as the next character is not the same quote as before)
. # match any character
)* # any number of times
\1 # until the corresponding closing quote
\s* # plus optional whitespace
",
"", RegexOptions.IgnorePatternWhitespace);
будет работать на вашем примере.
resultString = Regex.Replace(subjectString,
@"([""'])# Match a quote, remember which one
(?: # Then...
(?!\1) # (as long as the next character is not the same quote as before)
\\?. # match any escaped or unescaped character
)* # any number of times
\1 # until the corresponding closing quote
\s* # plus optional whitespace
",
"", RegexOptions.IgnorePatternWhitespace);
также будет обрабатывать экранированные кавычки.
Таким образом, он будет правильно преобразовывать
Hello "quoted \"string\\" and 'tricky"stuff' world
в
Hello and world