2017-02-15 99 views
0

我想添加CSS语法高亮显示到我在C#中的富文本框中。我会如何使用正则表达式突出显示标签名称/类别/ ID。对于HTM,我有这个目标,但我也想为CSS做些什么。CSS语法在c#中用正则表达式突出显示

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

回答

0

您可以使用此模式来匹配classes/ids:([\.#][_A-Za-z0-9\-]+)[^}]*{[^}]*}

Example

+0

'([\#_ A-ZA-Z0-9 \ - ] [_ A-ZA-Z0-9 \ - ] +)[^}] * {[^}] *}'这将是更好的 –

+0

我怎么做的CSS属性?我已经有一段时间在这个工作了一段时间,并没有得到任何好处。谢谢,如果你可以帮助 –

+0

不要担心,我已经为它的属性[@Zroq](http://stackoverflow.com/users/6454584/zroq) 这里'字符串属性= @“([A-Za- Z0-9 - ] * :)“;' –

相关问题