import re


def check_tag_balance(text, tag, recursive=False):
    """
    Check if all tags have a pair. Return True if yes, otherwise False.
    tag parameter must contains only name of the tag, for example, "b" for <b>.
    recursive flag must be True if nested tags are correct. The default value is False.
    """
    tags = re.findall(r"<(/?)\s*{}\b[^<>]*?>".format(tag), text, flags=re.I)
    tags = [cur_tag == "" for cur_tag in tags] # True for opening, False for closing

    balance = 0
    for cur_tag in tags:
        if cur_tag:
            balance += 1
        else:
            balance -= 1
        if balance < 0:
            return False
        if not recursive and balance > 1:
            return False
    if balance != 0:
        return False

    return True