Possible Duplicate:
What is a regular expression for parsing out individual sentences?
我想将大文本拆分成句子。我从答案 here 得到的正则表达式
string[] sentences = Regex.Split(mytext, @"(?<=[\.!\?])\s+");
所以我想到使用一种模式来进行分割,例如
如果 .
?
!
遵循 space
和一个capital
字母比做拆分。
大写字母表示句子的开头。
text = " Sentence one . Sentence e.g. two ? Sentence three.
sentence[1] = Sentence one
sentence[2] = Sentence e.g. two
对于有问题的情况,例如缩写,我打算进行替换
mytext.replace("e.g.","eg");
如何在正则表达式中实现这一点?
最佳答案
\p{Lt}
表示 Unicode 大写字母(包括重音符号等),因此
string[] sentences = Regex.Split(mytext, @"(?<=[.!?])\s+(?=\p{Lt})");
应该做你想做的事。
(请注意,我认为 .
或 ?
不需要在字符类中转义,因此我也删除了它们,但请检查这仍然是适用于这些角色。)
但是,请注意,这仍然会在例如先生。琼斯
...
关于c# - 改进正则表达式以将大文本拆分为句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14254636/