You can do something like this
var numbers = "3 7 6 5 4 3 2 1"; // list of numbers var iter = numbers.split(" ")[0] // get first number numbers = numbers.substr(iter.length+1) // chop off first number, and the space that follows it you can comment var rex = new RegExp("(?:\\d(?: |$)){" + iter + "}","") // create regex alert((numbers.match(rex)||[]).join("\n")) // a sample alert that joins the array to a string with an element on each line
Alternatively, if you want the first digit to determine the number of entries in the same array, several changes make it possible
var numbers = "3 7 6 5 4 3 2 1"; // list of numbers var iter = numbers.split(" ")[0] // get first number var rex = new RegExp("(?:\\d(?: |$)){" + (+iter+1) + "}","") // create regex alert((numbers.match(rex)||[]).join("\n")) // a sample alert that joins the array to a string with an element on each line
Regular joe
source share