def pattern_from_url(url_pattern):
    """
    Finds the internal stringified pattern for a URL across
    Django versions.

    Newer versions of Django use URLPattern, as opposed to
    RegexURLPattern.
    """
    if hasattr(url_pattern, 'pattern'):
        pattern = str(url_pattern.pattern)
    elif hasattr(url_pattern._regex, 'pattern'):
        pattern = str(url_pattern.regex.pattern)
    else:
        pattern = url_pattern._regex

    return pattern