import re


def get_cxx_close_block_regex(semicolon=False, comment=None, at_line_start=False):
###############################################################################
    """
    >>> bool(get_cxx_close_block_regex().match("}"))
    True
    >>> bool(get_cxx_close_block_regex(at_line_start=True).match("}"))
    True
    >>> bool(get_cxx_close_block_regex().match(" } "))
    True
    >>> bool(get_cxx_close_block_regex(at_line_start=True).match(" }; "))
    False
    >>> bool(get_cxx_close_block_regex(at_line_start=True).match(" } "))
    False
    >>> bool(get_cxx_close_block_regex(comment="hi").match(" } "))
    False
    >>> bool(get_cxx_close_block_regex(comment="hi").match(" } // hi"))
    True
    >>> bool(get_cxx_close_block_regex(comment="hi").match("} // hi  "))
    True
    >>> bool(get_cxx_close_block_regex(semicolon=True).match(" } "))
    False
    >>> bool(get_cxx_close_block_regex(semicolon=True).match(" } ; "))
    True
    >>> bool(get_cxx_close_block_regex(semicolon=True).match("};"))
    True
    >>> bool(get_cxx_close_block_regex(semicolon=True, comment="hi", at_line_start=True).match("};  // hi"))
    True
    >>> bool(get_cxx_close_block_regex(semicolon=True, comment="hi", at_line_start=True).match("};  // hi there"))
    False
    """
    semicolon_regex_str = r"\s*;" if semicolon else ""
    line_start_regex_str = "" if at_line_start else r"\s*"
    comment_regex_str   = r"\s*//\s*{}".format(comment) if comment else ""
    close_block_regex_str = re.compile(r"^{}}}{}{}\s*$".format(line_start_regex_str, semicolon_regex_str, comment_regex_str))
    return re.compile(close_block_regex_str)