1

I am using a regular expression to route my application, this is the regex I am using:

@/users/([a-zA-Z0-9\-\_]+)/posts@

But unfortunately it matches against these these urls too:

/users/:uid/posts/:pid
/users/:uid/posts/:pid/comment/:cid

But it shouldn't, it should match exact the same url so only:

/users/:uid/posts

What should I change in the regex to make it match the exact same string?

Thanks for help

1 Answer 1

3

You should include anchors for the beginning (^) and end ($) of the string:

@^/users/([a-zA-Z0-9\-\_]+)/posts/?$@

I also allowed for an optional / at the end of the URL.

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.