I have a regular expression, say /url.com\\/([A-Za-z]+)\\.html/, and I would like to replace it with new string $1: f($1), that is, with a constant
/url.com\\/([A-Za-z]+)\\.html/
new string $1: f($1)
When using String.replace, you can supply a callback function as the replacement parameter instead of a string and create your own, very custom return value.
String.replace
'foo'.replace(/bar/, function (str, p1, p2) { return /* some custom string */; });