var str = 'abcdefghijkl'; console.log(str.match(/.{1,3}/g));
foo.match(new RegExp('.{1,' + n + '}', 'g'));