0

URL structure look liks this: <domain>/<version>/<collection>/<sub-collection>/<page> where domain is anything a-zA-Z0-9\-\_, version is anything a-zA-Z0-9\-\_\. (But would likely be only 1.0, 1.1, 2.0.0 etc) and both collection and sub-collection are optional groups which follow <domain> restraints.

Current regex is: r'^(?P<domain_slug>[a-zA-Z0-9\-\_]*)\/(?P<version_slug>[a-zA-Z0-9\-\_\.]*)\/(?P<slug>[a-zA-Z0-9\-\_]+)\/$.

How can I capture optional positions, ensuring the last segment is always the page?

Additionally, is this even a good idea? Would it be better to just pass this through the Django URL conf and let a view function handle all the work?

Example URLs could include:
administration/5.0.3/reset-user-password
user/1.0/getting-started/setting-up-an-account
development/3.2/authentication/acl/creating-aco

1 Answer 1

1

(.*\/)([^\/]*)$ will put the page in $2 and something you'll have to parse in $1.

OP added:

The above did the trick. For reference, the full regex became (multi-lined for readability):

^(?P<domain>[a-zA-Z0-9\_\-]*)/ (?P<version>[a-zA-Z0-9\-\_\.]*)/ (?P<collections>.*)/ (?P<page>[^\/]*)$

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

1 Comment

This breaks things out the best for me - I just have to handle the collection group in-code, which is reasonable

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.