I am trying to match text between two delimiters, [% %] , and I want to get everything whether the string contains newlines or not.
the code
string strEmailContent = sr.ReadToEnd(); string commentPatt = @"\[%((\r\n?|\n).*(\r\n?|\n))%\]"; Regex commentRgx = new Regex(commentPatt, RegexOptions.Singleline);
Input Examples
//Successful [% New Comment %] other content from input //Match: [%\r\nNew Comment\r\n%] //Fail [% New Comment %] //Match: false //Successfully match single line with string commentPatt = @"\[%(.*)%\]"; //Match: [% New Comment %]
I do not know how to combine these two patterns according to both cases. Can anyone help?
source share