سؤال

I'm working on a forum and needed a replace function for the different tags. But it seems when it searchs for the [qoute] tag, it only search the first line, but I want it to search the whole string, since its blockquote and have multipe lines.

////Block Quote
regExp = new Regex(@"\[quote\](.*?)\[\/quote\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<blockquote>$1</blockquote>");

How can I make it do that?

هل كانت مفيدة؟

المحلول

. does not match newline by default. Use RegexOptions.Singleline to make . matches any character (including newline).

regExp = new Regex(@"\[quote\](.*?)\[/quote\]", RegexOptions.Singleline);

OR

regExp = new Regex(@"(?s)\[quote\](.*?)\[/quote\]");

BTW, you don't need to escape /.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top