How I can passing quantifier as variable in this regexp str.match(/^(\-)?\d+( (\-)?\d+){3}$/)

You can if you use something like this:

var q = "3";
var re = new RegExp("/^(\-)?\d+( (\-)?\d+){" + q + "}$");
if (re.test(str))
    //...

I try this:

var q = "3";
var re = new RegExp("/^(\-)?\d+( (\-)?\d+){" + q + "}$");
alert(re.test("1 2 3 4"));

but return false