Skip to content

Instantly share code, notes, and snippets.

@karltaylor
Last active July 7, 2017 11:28
Embed
What would you like to do?
Split string but keep delimiter
function split(string) {
return string.match(/\w+(?:\s\w+)*\W?/g)
}
console.log(split("string one, string two, thing three, four four."))
// ["string one,", "string two,", "thing three,", "four four."]
// https://regex101.com/r/1mn4J9/1/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment