<script>
var re = /((^\d)?\d{1,3})/g;
document.write(
[
"1234567890123".match(re).join(" "),
"123456789012345".match(re).join(" "),
"1234567890123456".match(re).join(" "),
"123456789012345678".match(re).join(" "),
"1234567890123456789".match(re).join(" ")
].join("<br>")
);
</script>