I'm trying to match any of several URL patterns in Javascript. The patterns are:
- The home page - the
/without anything after. - One of three solutions pages. Each
solutions(number)could be followed by a/and any characters after./solutions/99043or/solutions/99043/blah/solutions/60009or/solutions/60009/blah/solutions/40117or/solutions/40117/blah
- Search:
/searchfollowed by any characters after, e.g.?blah.
The RegEx I tried is as follows:
/\/$|\/solutions\/(99043|60009|40117)\/.*|\/search.*/
In this function:
(function () {
const urlPath = window.location.pathname;
if (urlPath.match(/\/$|\/solutions\/(99043|60009|40117)\/.*|\/search.*/)) {
console.log("urlPath", urlPath);
}
})()
It doesn't work in that everything seems to be matched. Anyone have any ideas where I went wrong?
Based on a comment, an example of a URL that matches but shouldn't:
/solutions/