When working with a node.js server, I encountered the need to modify URL addresses using JavaScript in a specific way:
For instance:
hostX/blah/dir1/name/id.js?a=b --> name.hostY/dir2.js?guid=id&a=b
Another example:
hostZ/dir1/name/id.js --> name.hostY/dir2.js?guid=id
This transformation is achieved by utilizing string.replace
and applying regular expressions defined within a configuration file.
My current attempt looks like this:
url.replace(/.*\\/dir1\\/(.*)\\/\\(d{2})\\.js?:(?=\?)(.*)/, "$1.hostC\/dir2.js?guid=$2");
The replacement string specifies ?guid=id
. Should I adjust the expression or the replacement string so that &originalQueryString
(with an ampersand) is included for Example 1, while nothing extra is added for Example 2?