If you want to split into a regular expression, you need to pass the regular expression to split as a parameter:
var str = "M50 0 L0 100 L100 100 L50 0 z M0 0 L100 0 L50 100 L0 0 Z"; var arr4String = str.split(/z|Z/); ^ ^
It produces:
["M50 0 L0 100 L100 100 L50 0 ", " M0 0 L100 0 L50 100 L0 0 ", ""] ^ ^ ^
(note the extra spaces, as the regex does not remove them).
If you want to trim the results, you can use:
...split(/\s*z\s*/i);
or you can just bind:
...split(/z/i).map(function (val) { return val.trim(); });
source share