目前我正在开发一个应用程序,它可以将一长列拆分为多个短列。为此,我将整个文本拆分为单词,但是目前我的正则表达式也将数字拆分。
我所做的是这样的:
str = "This is a long string with some numbers [125.000,55 and 140.000] and an end. This is another sentence.";
sentences = str.replace(/\.+/g,'.|').replace(/\?/g,'?|').replace(/\!/g,'!|').split("|");
结果是:
Array [
"This is a long string with some numbers [125.",
"000,55 and 140.",
"000] and an end.",
" This is another sentence."
]
期望的结果应该是:
Array [
"This is a long string with some numbers [125.000, 140.000] and an end.",
"This is another sentence"
]
我需要如何修改我的正则表达式才能实现这个目标?我需要注意一些可能会遇到的问题吗?或者只需搜索". "
、"? "
和"! "
就足够了吗?