Is there function which work as:
var regex=/\s*(\w+)/;
var s="abc def ";
var m1=regex.exec(s,0); // -> matches "abc"
var m2=regex.exec(s,3); // -> matches "def"
I know the alternative is:
var regex=/\s*(\w+)/;
var s="abc def ";
var m1=regex.exec(s); // -> matches "abc"
var m2=regex.exec(s.substring(3)); // -> matches " def"
But I worry about that if s is very long and s.substring is called many times, some implementation may work in bad efficiency in which copy long strings many times.
.{3}at the beginning of the regex.\w+and then walk each individual match? I'm guessing this is a reduction of your actual scenario, though...substringmakes a new object, but does not necessarily copy the character data. The length of your string may well be irrelevant. At any rate, to ensure you don't have an X-Y problem here, consider using thegflag, since you are probably trying to find words over and over again, right?