2014-06-26 19 views
0

我想文本主体分开,例如:如何将文本主体分为句子和/或分段符?

var str = "This is one. Two because of space break 
This is number three! 


And Four?!?!" 

运用herestr.match(/[^\.!\?]+[\.!\?]+/g)我得到以下3

[ 'This is one.', 
    ' Two because of space break\r\n This is number three!', 
    ' \r\n\r\n\r\n And Four?!?!' ] 

相反,我想有4种不同的清洁(无\ r \ n)值,因为分页符。我在匹配函数和这类作品之前尝试使用str.replace(/\r?\n/g,'.');,但我想知道是否有更简洁的方式,也许通过组合正则表达式?

我想获得:

['This is one.', 'Two because of space break', 'This is number three!', 'And Four?!?!'] 
+0

如果您停止使用Internet Explorer,问题就解决了! – adeneo

+0

我不使用IE浏览器,我正在使用Chrome – Squirrl

+0

短语分离的标准是什么?点或双倍空间? – jcaron

回答

1

这是你想要的吗?

str.match(/[^\s.!?]+[^.!?\r\n]+[.!?]*/g); 
+0

非常感谢 – Squirrl

相关问题