1
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

3
  • 2
    Use: match(/^\/app\/profile/.+/report$/) Commented Jul 19, 2018 at 11:08
  • Try /^\/app\/profile.*\/report$/ or /^\/app\/profile(?:\/.*)?\/report$/ Commented Jul 19, 2018 at 11:09
  • Just FYI: /^\/app\/profile/.+/report$/ would not match /app/profile/report. Commented Jul 20, 2018 at 7:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.