【发布时间】:2013-12-11 03:05:19
【问题描述】:
我的代码:
string comments = @"(\<\!\-\-.+?\-\-\>)";
MatchCollection commentMatches = Regex.Matches(rtb1.Text, comments);
foreach (Match m in commentMatches)
{
rtb1.SelectionStart = m.Index;
rtb1.SelectionLength = m.Length;
rtb1.SelectionColor = Color.Green;
}
我正在为我的学校项目开发一个 HTML 编辑器。我的问题是,注释部分不能写成多行。每当我换行时,整个注释代码都会变成黑色。我的问题你们都明白了。
【问题讨论】:
-
正则表达式中的
.表示 除换行符之外的任何字符,因此多行不会匹配您的模式。 -
这个答案可以解决你的问题:stackoverflow.com/questions/4654006/…
-
这是我做的一个小例子:dotnetfiddle.net/s9wm5j
-
@evanc3 非常感谢,evanc3!
标签: c# syntax colors richtextbox