由于换行,Regexp不能工作

本文关键字:Regexp 不能 工作 换行 于换行 | 更新日期: 2023-09-27 17:49:53

这是我目前所做的,试图转换:

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

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

但是引号标签之间的文本可以有换行符,这似乎使这不起作用,谁能告诉我如何使(.*?)包括匹配每个特殊字符?

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>"
            );

由于换行,Regexp不能工作

使用RegexOptions.Singleline。它改变了点(.)的含义,因此它匹配每个字符而不是除'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
            );

添加'n来表示换行符。.匹配除换行符

以外的所有内容