【发布时间】:2017-02-15 22:25:06
【问题描述】:
我想在 C# 中的富文本框中添加 CSS 语法突出显示。我将如何使用正则表达式来做到这一点,例如突出显示标签名称/类/ID。到目前为止,我已经为 HTM 做了这个,但我也想为 CSS 做。
string tags = @"<([/A-Za-z0-9]*)\b[^>]*>(.*?)";
tagMatches = Regex.Matches(rtb.Text, tags, RegexOptions.Multiline);
// getting attributes from the text
string attributes = @"[A-Za-z0-9-_]*=[A-Za-z0-9-_]*";
attributeMatches = Regex.Matches(rtb.Text, attributes);
// getting comments (inline or multiline)
string comments = @"(\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>)";
commentMatches = Regex.Matches(rtb.Text, comments, RegexOptions.Multiline);
// getting strings
string strings = "(\".+?\"|\'.+?\')";
stringMatches = Regex.Matches(rtb.Text, strings);
【问题讨论】:
标签: c# css syntax-highlighting