开发者

Regexp not working due to newlines?

This is what I have so far, trying to convert:

[quote="Tom":1m8ud0zc]blah blah[/quote:1m8ud0zc]

into

<table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by Tom</strong></em><br /><br />blah blah</td></tr></table>

But the text between the quote tags can have newlines, which seems to make this not work, can any tell me how to make (.*?) include matching every special char as well?

Message = Regex.Replace(Message,
                        @"\[quote=""(.*?)"":.*?](.*?)\[/quote:.*?]",
                        "<table width=\"99%\"><tr><td class=\"BBquote\"><strong><em>Originally posted by $1</strong></em><br /><br />$2</td></tr></table>"
      开发者_如何学编程      );


Use RegexOptions.Singleline. It changes the meaning of the dot (.) so it matches every character instead of every character except \n.

Message = Regex.Replace(Message,
                        @"\[quote=""(.*?)"":.*?](.*?)\[/quote:.*?]",
                        "<table width=\"99%\"><tr><td class=\"BBquote\"><strong><em>Originally posted by $1</strong></em><br /><br />$2</td></tr></table>",
RegexOptions.Singleline
            );


Add \n to express newline. The . matches everything except newline

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜