1

C# と Regex を使用して RichTextBox で音声認識を実行しようとしているため、ユーザーが [音声検索] をクリックすると、すべての音声マークと内部の音声が青色で強調表示されます。ただし、現在できることはスピーチマークを強調表示することだけなので、内部スピーチの検索と正規表現を組み合わせる方法についてはよくわかりません。

public void FindSpeech()
{ 

   Regex SpeechMatch = new Regex("\"");

   TXT.SelectAll();
   TXT.SelectionColor = System.Drawing.Color.Black;
   TXT.Select(TXT.Text.Length, 1);
   int Pos = TXT.SelectionStart;

   foreach (Match Match in SpeechMatch.Matches(TXT.Text))
   {
           TXT.Select(Match.Index, Match.Length);
           TXT.SelectionColor = System.Drawing.Color.Blue;
           TXT.SelectionStart = Pos;
           TXT.SelectionColor = System.Drawing.Color.Black;
   }
}
4

2 に答える 2

1

このパターンを使用できます。主な関心は、引用符内のエスケープされた引用符に一致できることです。

Regex SpeechMatch = new Regex(@"\"(?>[^\\\"]+|\\{2}|\\(?s).)+\"");

パターンの詳細:

\"             # literal quote
(?>            # open an atomic(non-capturing) group
    [^\\\"]+   # all characters except \ and "
  |            # OR
    \\{2}      # even number of \ (that escapes nothing)
  |            # OR
    \\(?s).    # an escaped character
)+             # close the group, repeat one or more times (you can replace + by * if you want)
\"             # literal quote
于 2013-11-03T16:53:13.540 に答える
1

Try this:

Regex SpeechMatch = new Regex("\".+?\"");
于 2013-11-04T21:15:49.593 に答える