import re


def get_tensor_names(string_obj):
    """
    Get tensor names from the given string.

    :param obj: a string representing an object from gc.get_objects()
    :return: the name of the tensor variable

    >>> names = get_tensor_names(log2)
    >>> assert len(names) == 3
    >>> assert names[0] == "tensor1"
    >>> assert ['tensor1', 'tensor2', 'tensor3'] == names

    >>> names = get_tensor_names(log1)
    >>> assert len(names) == 1
    >>> assert ["tensor1"] == names

    """
    # There can be more than a single tensor name in the string.
    # This pattern does not overlap in the object from gc.
    pattern = "'(\w+)': tensor\("
    # pos = string_obj.find(pattern)
    return re.findall(pattern, string_obj)