import re


def get_subroutine_end_regex(name):
###############################################################################
    """
    >>> bool(get_subroutine_end_regex("fake_sub").match("end subroutine fake_sub"))
    True
    >>> bool(get_subroutine_end_regex("fake_sub").match("end subroutine fake_sub_2"))
    False
    >>> bool(get_subroutine_end_regex("fake_sub").match("  end  subroutine  fake_sub "))
    True
    >>> bool(get_subroutine_end_regex("fake_sub").match("!end  subroutine  fake_sub "))
    False
    >>> bool(get_subroutine_end_regex("fake_sub").match("end function fake_sub"))
    True
    >>> bool(get_subroutine_end_regex("fake_sub").match("end function fake_sub_2"))
    False
    """
    subroutine_end_regex_str = r"^\s*end\s+(subroutine|function)\s+{}\s*$".format(name)
    return re.compile(subroutine_end_regex_str)