'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=''):

    base_regex = '(?P<{lookup_prefix}{lookup_field}>{lookup_value})'
    lookup_field = getattr(viewset, 'lookup_field', 'pk')
    try:
        lookup_value = viewset.lookup_value_regex
    except AttributeError:
        lookup_value = '[^/.]+'
    return base_regex.format(lookup_prefix=lookup_prefix, lookup_field=lookup_field, lookup_value=lookup_value)
