我需要拆分一个保留非空白的句子字符串,如.
或,
。我需要将它们包含在被拆分的数组字符串中。不在他们自己的数组索引中。拆分一个字符串,但保留逗号
const regex = /\W(?:\s)/g
function splitString (string) {
return string.split(regex)
}
console.log(splitString("string one, string two, thing three, string four."))
// Output ["string one", "string two", "thing three", "string four."]
// Desired ["string one,", "string two,", "string three,", "string four."]
期望的输出是什么? – Vineesh
期望的输出是什么? – 2017-07-07 11:16:26
- [“String one,”,“string two”,“final string。”] –