Last active
September 2, 2016 16:58
-
-
Save timmarinin/1733133b02696f87c64224916d1c52ba to your computer and use it in GitHub Desktop.
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
function groupByUndefined(col) { | |
var ret = [] | |
var current = [] | |
for (var i = 0; i < col.length; i++) { | |
if (typeof col[i] !== 'undefined') current.push(col[i]) | |
else { | |
ret.push(current) | |
current = [] | |
} | |
} | |
ret.push(current) | |
return ret | |
} | |
function splitByComma(txt) { | |
var matches = txt.split(/(\(.*?\))|,/) | |
return groupByUndefined(matches).map(x => x.join('')).filter(x=>x) | |
} | |
// example: | |
splitByComma('some text, like this, is (inevitable, though) entered by, who\'d guess it, user!') | |
// becomes ["some text", " like this", " is (inevitable, though)", " entered by", " who'd guess it", " user!"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment