문제

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