fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.IO;
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var str = @"//Successful
  9. [%
  10. New Comment
  11. %] other content from input
  12.  
  13. //Match: [%
  14. New Comment
  15. %]
  16.  
  17. //Fail
  18. [% New Comment %]
  19.  
  20. //Match: false
  21.  
  22. //Successfully match single line with
  23. string commentPatt = @""\[%(.*)%\]"";
  24.  
  25. //Match: [% New Comment %]";
  26. var rx = new Regex(@"(?s)\[%(.*?)%]");
  27. var res = rx.Matches(str);
  28. foreach (Match m in res)
  29. Console.WriteLine(m.Groups[1].Value);
  30. }
  31. }
Success #stdin #stdout 0.12s 24304KB
stdin
Standard input is empty
stdout
  New Comment


New Comment

 New Comment 
(.*)%\]";

//Match: [% New Comment