human
Complete the below
def _reverse_url_pattern(url_pattern, *args):

    ''''Turns a regex that matches a url back into a url by replacing
    the url pattern\'s groups with the given args. Removes \'^\' and \'$\'
    from the result.
    Args:
    url_pattern: A pattern used to match a URL.
    args: list of values corresponding to groups in url_pattern.
    Returns:
    A string with url_pattern\'s groups filled in values from args.
    Raises:
    CannotReversePattern if either there aren\'t enough args to fill
    url_pattern\'s groups, or if any arg isn\'t matched by the regular
    expression fragment in the corresponding group.'
    '''

=====
What is a the Python program you requested?
assistant
#Here is the Python program you requested.
    group_index = [0]
    def expand_group(match):
        group = match.group(1)
        try:
            value = str(args[group_index[0]])
            group_index[0] += 1
        except IndexError:
            raise CannotReversePattern('Not    enough    arguments    in    url    tag')
        if (not re.match((group + '$'), value)):
            raise CannotReversePattern(("Value    %r    doesn't    match    (%r)" % (value, group)))
        return value
    result = re.sub('\\(([^)]+)\\)', expand_group, url_pattern.pattern)
    result = result.replace('^', '')
    result = result.replace('$', '')
    return result