In a node.js server I need to convert URL addresses using JavaScript as follows:
Example 1:
hostA/blah/dir1/name/id.js?a=b --> name.hostC/dir2.js?guid=id&a=b
Example 2:
hostB/dir1/name/id.js --> name.hostC/dir2.js?guid=id
The conversion is done with string.replace using regular expressions detailed inside a configuration file.
So far I have:
url.replace(/.*\\/dir1\\/(.*)\\/\\(d{2})\\.js?:(?=\?)(.*)/, "$1.hostC\/dir2.js?guid=$2");
The replacing string specifies ?guid=id. How do I alter the expression or the replacing string so that &originalQueryString (note the ampersand) will be added in case of example 1 and nothing added in case of example 2?
?to a&(hence the difficulty).