-1

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?

Dreams
  • 8,288
  • 10
  • 45
  • 71

2 Answers2

2

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();
}
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
1

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('.'))
Pavan Teja
  • 3,192
  • 1
  • 15
  • 22