def get_last_server_gtid(gtid_set, server_uuid):
    """Get the last GTID of the specified GTID set for the given server UUID.

    This function retrieves the last GTID from the specified set for the
    specified server UUID. In more detail, it returns the GTID with the greater
    sequence value that matches the specified UUID.

    Note: The method assumes that GTID sets are grouped by UUID (separated by
    comma ',') and intervals appear in ascending order (i.e., the last one is
    the greater one).

    gtid_set[in]        GTID set to search and get last (greater) GTID value.
    server_uuid[in]     Server UUID to match, as a GTID set might contain data
                        for different servers (UUIDs).

    Returns a string with the last GTID value in the set for the given server
    UUID in the format 'uuid:n'. If no GTID are found in the set for the
    specified server UUID then None is returned.
    """
    uuid_sets = gtid_set.split(',')
    for uuid_set in uuid_sets:
        uuid_set_elements = uuid_set.strip().split(':')
        # Note: UUID are case insensitive, but can appear with mixed cases for
        # some server versions (e.g., for 5.6.9, lower case in server_id
        # variable and upper case in GTID_EXECUTED set).
        if uuid_set_elements[0].lower() == server_uuid.lower():
            last_interval = uuid_set_elements[-1]
            try:
                _, end_val = last_interval.split('-')
                return '{0}:{1}'.format(server_uuid, end_val)
            except ValueError:
                # Error raised for single values (not an interval).
                return '{0}:{1}'.format(server_uuid, last_interval)

        else:
            # Skip uuid_set if it does not match the current server uuid.
            continue
    return None