【问题标题】:splitting sentences using regex使用正则表达式拆分句子
【发布时间】:2009-12-15 02:47:13
【问题描述】:

我想将文本(使用正则表达式)拆分为一个点后跟一个空格或一个点后跟换行符 (\n)

我正在使用 c# .Net

感谢您的回答!

【问题讨论】:

    标签: c# regex split


    【解决方案1】:
    using System.Text.RegularExpressions;
    string[] parts = Regex.Split(mytext, "\.\n|\. "); 
    # or "\.\s" if you're not picky about it matching tabs, etc.
    

    【讨论】:

      【解决方案2】:

      正则表达式

      /\.\s/
      

      将匹配文字 . 后跟空格。

      【讨论】:

      • C# 中没有文字正则表达式 (/.../)。
      【解决方案3】:

      您不需要正则表达式。只需使用带有字符串数组的string.Split 的重载:

      string[] splitters = new string[] { ". ", ".\t", "." + Environment.NewLine };
      string[] sentences = aText.Split(splitters, StringSplitOptions.None);
      

      【讨论】:

        猜你喜欢
        • 2014-03-24
        • 2016-08-04
        • 1970-01-01
        • 1970-01-01
        • 2016-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多