Skip to content

Instantly share code, notes, and snippets.

@FireyFly
Forked from cowboy/am-i-being-dumb.js
Created July 24, 2012 17:15
Show Gist options
  • Save FireyFly/3171276 to your computer and use it in GitHub Desktop.
Save FireyFly/3171276 to your computer and use it in GitHub Desktop.
JavaScript: split on :, handling escaped \:
// Split colon-separated parts, unescaping (but not splitting on) any \:
function split(str) {
return str.match(/(?:\\:|[^:])+/g).map(function(part) {
return part.replace(/\\:/g, ':')
});
}
// Eg.
split("foo:bar\\:baz\\:boo:qux") // ["foo", "bar:baz:boo", "qux"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment