xxxxxxxxxx
// Declare the regex as a private static readonly field
private static readonly Regex rx = new Regex(@"\[data\].*?\[/data\]", RegexOptions.Compiled);
// and then in the caller ....
writer.WriteLine(string.Join(string.Empty, rx.Matches(line).Cast<Match>().Select(p => p.Value).ToArray()));