2

i have the following pattern : /^\/(?P<slug>.+)$/ that match : /url.

My problem is that it also match /url/page, how to ignore /in this regex ?

The pattern should:

  • Pattern match : /url
  • Pattern don't match : /url/page

Thanks in advance.

1 Answer 1

3

This should do it:

/^\/(?P<slug>[^\/]+)$/

[^\/] matches every character that is not a slash (^ at the beginning of a character class negates the class). I recommend to have a look at http://www.regular-expressions.info/ to learn more about regular expressions.

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.