JSFiddle - React, Tailwind, and code Playground

JavaScript

var string ="a%20sentence%20divided%20by%20spaces_123456.html";
// replace %20 with +
var regex1 = '%20';
var re1 = new RegExp(regex1, 'g');
string = string.replace(re1, '+');
// trailing _12345
var regex2 = '([^_]+)_([^.]+)(\.html)$';
var re2 = new RegExp(regex2);
string = string.replace(re2,'$1$3');
alert(string);