import re


def check_segmentation(prefix, lines, contains):
    """Check that the output consists of the neat repetition of (contents)"""
    reg = re.compile(r"^" + prefix + r"\(\d+, \d+\): \[(.*)\]$")
    allOutput = ""
    for _, line in enumerate(lines):
        result = reg.match(line)
        if result:
            allOutput += result.group(1)
    assert(allOutput != "")
    reg = re.compile(r"^((" + contains + ")+)(.*)$")
    result = reg.match(allOutput)
    if not result:
        print("Expected repetition of \"%s\" is not found in \"%s\"..." %
              (contains, allOutput[0:len(contains)+1]))
        return False
    elif len(result.group(3)) == 0:
        return True
    else:
        print("Output is not consistent after byte %d (...\"%s\");"
              " continuing with \"%s\"..." %
              (len(result.group(1)), result.group(2),
               result.group(3)[0:len(contains)+1]))
        return False