2015-09-04 32 views
1

我已经继承了一个电子邮件数据库表,其中已经处理了保存的正文文本以删除变音符号,但此过程还取出了Environment.Newline字符。我可以编写一个正则表达式来识别此模式([。!?。??] \ {0} \ w),因为在句子标记的典型结尾(例如:。!?)之间不存在空格,下一句,但我看不到如何在两个字符之间插入换行符。在预处理文本中替换丢失的“换行符”

E:G:“这是第一paragraph.And此的端部是所述第二的开始

我要插入一个新行(在之间这种情况下,‘HA’)和地方这类型的模式发生任何帮助将不胜感激(我使用C#.NET 4.5) - 我已经花了几个小时的RegExBuddy,看不到如何做到这一点,请原谅我的无知

回答

0

首先, d考虑推送获取原始消息而不是诉诸于这些措施,因为结果不会很完美。

您可以使用正则表达式[\.\!\?]\b,它被定义为标点符号,后面跟着单词的开头。

示例代码:

static void Main(string[] args) 
{ 
    Console.WriteLine(RestoreNewlines("This is the end of the first paragraph.And this is the start of the second. This is the start of the third.")); 
    Console.WriteLine(RestoreNewlines("Example of a case.txt where it fails.")); 
} 

private static readonly Regex PunctuationWithoutFollowingWhitespaceRegex = new Regex(@"[\.\!\?]\b"); 

static string RestoreNewlines(string input) 
{ 
    return PunctuationWithoutFollowingWhitespaceRegex.Replace(input, match => match.Value + Environment.NewLine); 
} 

输出:

This is the end of the first paragraph. 
And this is the start of the second. This is the start of the third. 
Example of a case. 
txt where it fails. 
+0

PS,我会恢复的邮件,如果他们被查阅:他们被弹出通过他们使用的工具的服务器。 –