I have a string format inside of a string variable:
\"{0} Hello World {1}\"
I need to split it into something like this:
\"{0}\
You can just filter out the empty strings if you want:
var s = "{0} Hello World {1}"; s.split(/({\d+})/).filter(Boolean);
which returns
["{0}", " Hello World ", "{1}"]