Why not store the regex string (or better, the regex itself) as the key for the map so that you don't need to do a route.replaceAll() on it everytime?
Meanwhile the loop can use Map.prototype.entries() and become something like
for (const [route, val] of this.routes.entries()) {
const regex = new RegExp(`^(${route.replaceAll(/\[.*\]/g, "(.*)")})$`)
if (regex.test(path)) {
return val;
}
}
for (const [route, val] of this.routes.entries()) {
const regex = new RegExp(`^(${route.replaceAll(/\[.*\]/g, "(.*)")})$`)