Something like this (untested!):
String pattern = Regex.Escape(@"<script>") + @"(?<inner_text>.*@)" + Regex.Escape(@"</script>");
Regex rx = new Regex(pattern);
foreach (Match m in rx.Matches(input))
{
string captured = m.Groups["inner_text"];//maybe a .Value is missing?!
}
//OR:
rx.Replace(input,MyMatchEvaluator);
//...
string MyMatchEvaluator(Match m)
{
return @"<script>" + MyTransformingFunction(m.Groups["inner_text"]) + @"</script>";
}
UPDATE:
I got the non-greedy flag wrong. somehow I thougt it was '@', but in fact it is '?'. The fixed pattern:
String pattern = Regex.Escape(@"<script>") + @"(?<inner_text>.*?)" + Regex.Escape(@"</script>");
You could replace the '*' with a '+' to only match non-empty script tags.
UPDATE #2: the '@' was in my head because of the VisualStudio regex "Find" - it's the non-greedy version of '*' for VisualStudio's "Find in Files"