Reputation: 3272
const profileActive = location.pathname && location.pathname.match(/^\/app\/profile/) ? "profileActive" : "";
My case need to match:
/app/profile/ANYTHINGHERE/report
At the moment it matches just:
/app/profile/
Any help to express a match anything expression between / /
Thanks
Upvotes: 1
Views: 33
Reputation: 626927
You may use either
/^\/app\/profile(?:\/.*)?\/report$/
See this regex demo
Or, if there should only be 1 subpart in between:
/^\/app\/profile(?:\/[^\/]+)?\/report$/
See this regex demo.
The (?:\/[^\/]+)?
will match an optional sequence of /
and 1+ chars other than /
while (?:\/.*)?
will match an optional sequence of a /
followed with any 0+ chars.
Upvotes: 1