Split string into sentences in javascript

后端 未结 8 1175
悲哀的现实
悲哀的现实 2020-11-29 06:08

Currently i am working on an application that splits a long column into short ones. For that i split the entire text into words, but at the moment my regex splits numbers to

8条回答
  •  佛祖请我去吃肉
    2020-11-29 06:26

    you forgot to put '\s' in your regexp.

    try this one

    var str = "This is a long string with some numbers [125.000,55 and 140.000] and an end. This is another sentence.";
    var sentences = str.replace(/\.\s+/g,'.|').replace(/\?\s/g,'?|').replace(/\!\s/g,'!|').split("|");
    console.log(sentences[0]);
    console.log(sentences[1]);
    

    http://jsfiddle.net/hrRrW/

提交回复
热议问题