R – URL regex in django with limited set of words

djangoregexurl

Given the following django URL conf. entry:

url(r'^(?P<obj_ctype_name>\w+)/(?P<obj_id>\d+)/$',
    views.obj_view,
    name='obj_view')

How would I rewrite the parameter (?P<obj_ctype_name>\w+) to enforce that
it may only be one of "foo" "bar" or "baz" and still keep it as a named
parameter?

Best Answer

(?P<obj_ctype_name>foo|bar|baz)