-
-
Save FireyFly/3171276 to your computer and use it in GitHub Desktop.
JavaScript: split on :, handling escaped \:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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