using System; using System.Text.RegularExpressions; using System.IO; public class Test { public static void Main() { var str = @"//Successful [% New Comment %] other content from input //Match: [% New Comment %] //Fail [% New Comment %] //Match: false //Successfully match single line with string commentPatt = @""\[%(.*)%\]""; //Match: [% New Comment %]"; var rx = new Regex(@"(?s)\[%(.*?)%]"); var res = rx.Matches(str); foreach (Match m in res) Console.WriteLine(m.Groups[1].Value); } }