Split string into sentences in javascript

后端 未结 8 1183
悲哀的现实
悲哀的现实 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:23

    Use lookahead to avoid replacing dot if not followed by space + word char:

    sentences = str.replace(/(?=\s*\w)\./g,'.|').replace(/\?/g,'?|').replace(/\!/g,'!|').split("|");
    

    OUTPUT:

    ["This is a long string with some numbers [125.000,55 and 140.000] and an end. This is another sentence."]
    

提交回复
热议问题