I have a string
var stringP= "hi".rand(1,10)." my".rand(10,100)."name is ".rand(23,54).rand(1,4)
Pattern is
rand(from,to)
Need to get
hi5 my54name is 335
It possible to use something like that?
stringP.replace(/rand(*,*)/g, function(match){
return match.replace(rand(*,*),Math.floor(Math.random() * (to - from + 1) + from));
});
Yes, nearly everything is possible. Yet, you want to use a [one!] proper regular expression, and a proper replace function: