I have looked into this problem, but I couldn't find a good answer. So here is my code:
var str = '000100111000010110'
var length = 2;
var temp = new Array(str.match(/.{length}/g));
But this doesn't work.
It's very important to keep the length of a variable, and if I don't have to, I won't use a regular expression.