【发布时间】:2013-09-20 10:34:16
【问题描述】:
目前我正在开发一个将长列拆分为短列的应用程序。为此,我将整个文本拆分为单词,但目前我的正则表达式也拆分了数字。
我要做的是:
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"
]
我必须如何更改我的正则表达式才能实现这一目标?我需要注意我可能遇到的一些问题吗?或者搜索". "、"? " 和"! " 是否足够好?
【问题讨论】:
-
你能改变字符串还是这不是一个选项?
-
您是否正在寻找能够获得所需结果的有效正则表达式(或者)您已经知道这一点并希望就它的其他潜在问题提出建议?
-
@Beejee:我可以操纵字符串。
-
'或者搜索
". "、"? "和"! "是否足够好?' - 不,因为它不允许使用". "的缩写:“我们应该去联邦调查局还是语法警察?”
标签: javascript regex