我需要拆分一個保留非空白的句子字符串,如.
或,
。我需要將它們包含在被拆分的數組字符串中。不在他們自己的數組索引中。拆分一個字符串,但保留逗號
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。」] –