<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def gen_url_regex(resource):
    " URL regex for resource class generator. "

    if resource._meta.parent:
        yield resource._meta.parent._meta.url_regex.rstrip('/$').lstrip('^')

    for p in resource._meta.url_params:
        yield '%(name)s/(?P<%(name)s>[^/]+)' % dict(name=p)

    if resource._meta.prefix:
        yield resource._meta.prefix

    yield '%(name)s/(?P<%(name)s>[^/]+)?' % dict(name=resource._meta.name)