我有一个这样的字符串...
"1.first. 2.second. 3.third"
我希望使用 JavaScript split 让它像这样
["1.first.", "2.second", "3.third"]
我看到
C#
是这样的Regex.Split(txt, "[0-9]+\\.");
我尝试使用这个... 描述.split(/([0-9]+)/)
但结果是这样的
[
"1",
". first",
"2",
". second ",
"3",
".third",
"23",
"two three",
"4",
".four"
]
只需使用
Array::flatMap()
并使用带有后向断言的正则表达式分割单词:
console.log(["1.first.", "2.second", "3.third"].flatMap(item => item.split(/(?<=\.)/)));