I'm trying to test a location.pathname. I'm passing a path to a function with regex. The path can be:
/dashboard
/dashboard/orders
And location.pathname can be:
/dashboard
/dashboard/orders
/dashboard/orders/5ea5c95684c28d4b7ff688e1
/dashboard/orders/anyOtherId
What I want to do is when passing /dashboard/orders/5ea5c95684c28d4b7ff688e1 as location.pathname it matches only with the path /dashboard/orders and not with /dashboard.
Testing Regex in https://regexr.com/ I could make it work: \/dashboard\/*, then I tried to implement it in javascript:
const matcher = new RegExp(`${path}\/*`)
matcher.test(location.pathname)
However, when I pass a path = /dashboard/orders and location.pathname = /dashboard/orders/5ea5c95684c28d4b7ff688e1 it matches with /dashboard and /dashboard/orders. I need it to match only with /dashboard/orders. /dashboard must match only when path is /dashboard and location.pathname = /dashboard.
How can I achieve this?
Thanks in advance
Edit: To be more clear, I need it to return true when path is /dashboard/orders and location.pathname is /dashboard/orders or /dashboard/orders/5ea5c95684c28d4b7ff688e1.
But it must return false when path is /dashboard and location.pathname is /dashboard/orders or /dashboard/orders/5ea5c95684c28d4b7ff688e1
\/dashboard\/orders\/*then?string.startsWith(substring [, position]);ref: techonthenet.com/js/string_startswith.phplocation.pathnameis/dashboard/orders/5ea5c95684c28d4b7ff688e1, but when it's just/dashboard/ordersit matches withpath/dashboard