It's not stated in your question so I'll provide a possible solution for single-line quotations:
public static void Main(string[] args)
{
const string MatchQuotedExp = @"(\x22|\x27)((?!\1).|\1{2})*\1";
Regex regex = new Regex(MatchQuotedExp);
string input = @"""Foo"" Bar ""Foo"" Bar ""Foo""!
""Bar"" Foo ""Bar"" Foo ""Bar""!";
foreach (Match match in regex.Matches(input))
{
input = Regex.Replace(
input,
match.Value,
match.Value.ToUpperInvariant());
}
Console.WriteLine(input);
}
For multi-line quotation support add RegexOptions.Singleline
when creating the regex
.
With multi-line support, the input:
// "Foo" Bar "Foo" Bar "Foo"!
// "Bar" Foo "Bar" Foo "Bar"! "Multi
// line" blah
will be converted to:
// "FOO" Bar "FOO" Bar "FOO"!
// "BAR" Foo "BAR" Foo "BAR"! "MULTI
// LINE" blah
Also note that this will blow up if ANY of the quotations contain an odd number of "
inside. :)