def sectioner(doc_string, regex):
    """
    Find all regex-identifiable elements in a document
    @param doc_string: UNICODE string containing dcoument in which elements are
    to be identified
    @param regex: compiled regexp expression to perform this match
    @returns: array of (begin, end) tuples, sorted. Each tuple is the beginning
    and ending character offset of the element found
    """
    matches=regex.search(doc_string)
    header_pos = []
    tail=0
    while matches is not None:
        header_pos.append((tail + matches.span()[0], tail + matches.span()[1]))
        tail = tail + matches.span()[1]
        matches=regex.search(doc_string[tail:])

    return header_pos