2017-02-15 47 views
0

C#のリッチテキストボックスにCSS構文の強調表示を追加します。たとえば、正規表現を使用してそのようにします。タグ名/クラス/ 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

このパターンを使用して、クラス/ ID:([\.#][_A-Za-z0-9\-]+)[^}]*{[^}]*}と一致させることができます。

Example

+0

'([\#_ A-ZA-Z0-9 \ - ] [_ A-ZA-Z0-9 \ - ] +)[^}] * {[^}] *}'これは良いでしょう –

+0

私はCSSのプロパティのためにそれをやりますか?私はこれをしばらくの間作業しており、どこにも行きませんでした。あなたが助けることができればありがとう –

+0

私はプロパティ[@ Zroq](http://stackoverflow.com/users/6454584/zroq) のためにそれを働いたことを心配しないでください 'string attributes = @"([A-Za- z0-9 - ] * :) ";" –