【问题标题】:C# Get Speech From Within Speech MarksC# 从语音标记中获取语音
【发布时间】:2013-11-14 07:58:53
【问题描述】:

我正在尝试使用 C# 和正则表达式在 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;
   }
}

【问题讨论】:

  • 你能告诉我们输入的文本吗?你想精确搜索/匹配什么?
  • 一个示例字符串将非常有用。

标签: c# regex find richtextbox speech


【解决方案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

【讨论】:

  • 它没有用。我有多个编译器错误;大部分字符串区域都带有下划线。我该怎么办?
  • @Joe:想法就是这种模式,但我不确定你必须转义多少次双引号和反斜杠。
  • @CasimiretHippolyte 只需删除@。使用时不必转义反斜杠,但必须双引号
【解决方案2】:

试试这个:

Regex SpeechMatch = new Regex("\".+?\"");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    相关资源
    最近更新 更多