using System; using System.Text.RegularExpressions; public class Test { public static void Main() { string text = @"My arbitrary content.... ```c# public class Foo { //Some code } ``` Some text ```c# public class Bar { //Some code } ``` My other arbitrary content...."; text = Regex.Replace( text, @"^```c#\r?\n(.*?)```\r?\n", "$1", RegexOptions.Singleline | RegexOptions.Multiline); Console.WriteLine(text); } }