Here is my code
"test.html".replace(/(?=\.[^.]+$)/g, Math.floor((Math.random() * 1000000) + 1))
How to convert test.html to random number.html like 38475.html?
Here is my code
"test.html".replace(/(?=\.[^.]+$)/g, Math.floor((Math.random() * 1000000) + 1))
How to convert test.html to random number.html like 38475.html?
if regex is not mandatory :), then try
Math.floor((Math.random() * 1000000) + 1) + "." + "test.html".split( "." ).pop();
create a method
function randomizeFileName( fileName )
{
return Math.floor((Math.random() * 1000000) + 1) + "." + fileName.split( "." ).pop();
}
Why do you have to use regex here? you can just use the randaom number appended with file extension of actual file.
var fileName="test.html";
fileName= Math.floor((Math.random() * 1000000) + 1)+fileName.substr(fileName.lastIndexOf('.'))