Skip to content

Instantly share code, notes, and snippets.

@scottrippey
scottrippey / Example.js
Created November 8, 2011 20:32
JavaScript that uses a Regex to split a string, ensuring balanced parenthesis and balanced quotes.
var input = "a, b, (c, d), (e, (f, g), h), 'i, j, (k, l), m', 'n, \"o, 'p', q\", r'";
var result = SplitBalanced(input, ",");
// Results:
["a",
" b",
" (c, d)",
" (e, (f, g), h)",
" 'i, j, (k, l), m'",
" 'n \"o, 'p', q\", r'"];