I've changed my query parameters format from &Key=Value to /Key/Value.
Now I'm trying to parse them in the url using regex. Not sure what I'm doing wrong but this is my code
Example url path: http://localhost/MyApp/#!/Page1/SubPage1/SubPage2/Key/value-example
let re = new RegExp(`^.*/(Key)/([a-zA-Z0-9]+).*$`);
while (match = re.exec(url)) {
params[match[1]] = match[2];
}
It ends in a infinite loop
What am I doing wrong?
gmodifier. The regex index is not advanced andwhilealways starts from the string start. Also, add-if there can be-in the value:let re = new RegExp(`^.*/(Key)/([a-zA-Z0-9-]+).*$`, "g");. However, if you do not expect multiple matches, just replacewhilewithif, then the regex can be used withoutg,new RegExp(`^.*/(Key)/([a-zA-Z0-9-]+).*$`).