'Given a viewset, return the portion of URL regex that is used
to match against a single instance.
Note that lookup_prefix is not used directly inside REST rest_framework
itself, but is required in order to nicely support nested router
implementations, such as drf-nested-routers.
https://github.com/alanjds/drf-nested-routers'

def get_lookup_regex(self, viewset, lookup_prefix=u''):

    base_regex = u'(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})'
    lookup_field = getattr(viewset, u'lookup_field', u'pk')
    lookup_url_kwarg = (getattr(viewset, u'lookup_url_kwarg', None) or lookup_field)
    lookup_value = getattr(viewset, u'lookup_value_regex', u'[^/.]+')
    return base_regex.format(lookup_prefix=lookup_prefix, lookup_url_kwarg=lookup_url_kwarg, lookup_value=lookup_value)
