我想分割文本正文,例如:
var str = "This is one. Two because of space break
This is number three!
And Four?!?!"
使用 here 中的 str.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)值。我尝试在 match 函数之前使用 str.replace(/\r?\n/g,'.');
,但我想知道是否有更干净的方法组合正则表达式?
我想得到:
['This is one.', 'Two because of space break', 'This is number three!', 'And Four?!?!']
最佳答案
这是你想要的吗?
str.match(/[^\s.!?]+[^.!?\r\n]+[.!?]*/g);
关于javascript - 如何将文本正文拆分为句子和/或段落分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24441291/