Skip to content

Instantly share code, notes, and snippets.

@karltaylor
Last active July 7, 2017 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karltaylor/990695edc3a66d65d46acf69511facce to your computer and use it in GitHub Desktop.
Save karltaylor/990695edc3a66d65d46acf69511facce to your computer and use it in GitHub Desktop.
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