function [FA_B, NUC_B, RA_B, FA_C, NUC_C, RA_C] = matchnot0Reads(Matches, FR, SeqF, SeqR, FB, RB, LIB, kind)

% create regular expression that will be used to search for reads    
expres = MakemisExpression(FB, RB, LIB, kind);

% matching in done in chunks to avoid overloading the memory during the
% regexp search. This chunk is controlled only locally. It might not be 
% necessary in the future, where entire aligned2unique function is written
% as chunky-function that reads and processes input in chunks.
CHUNK=100000;

% fuse all nucleotides into one long string; insert an extra space %%%%%%%%
cMatches={};
if size(Matches,1)>CHUNK
    for ii=1 : floor( size(Matches,1)/CHUNK )
        cMatches{ii}=Matches( CHUNK*(ii-1)+1:CHUNK*ii );
    end
    cMatches{ii+1}=Matches( CHUNK*ii+1:end );
else
    cMatches{1}=Matches;
end
    
%%%%%%%%%%%%%%%%%%%% loop through sub-Matches to find the library %%%%%%%%%
%%%%%%%%%%%%%%%%%%%% using regexp constructed above %%%%%%%%%%%%%%%%%%%%%%%
out_B = [];
out_C = [];
for ii=1:numel(cMatches)
    SP = char(32*ones(size(cMatches{ii},1),1));
    input = sprintf('%s\r\n', [FR(cMatches{ii},:) SP]');
    SeqF_input = sprintf('%s\r\n', [SeqF(cMatches{ii},:) SP]');
    SeqR_input = sprintf('%s\r\n', [SeqR(cMatches{ii},:) SP]');
    Seq_diff_idx = sparse(SeqF_input ~= SeqR_input);
    
    % search for the regular expression (the slowest step)
    [temp_1,temp_2] = regexp(input,expres,'tokenExtents','names');
    idx_B = [];
    idx_C = [];
    if(size(temp_1,1)>0)
        for jj = 1:size(temp_1,2)
            temp_idx = temp_1{jj};
            
            flag_B = sum(Seq_diff_idx([temp_idx(1,1):temp_idx(1,2),...
                temp_idx(3,1):temp_idx(3,2)]))>0;
            
            flag_C = sum(Seq_diff_idx([temp_idx(2,1):temp_idx(2,2)]))>0;
            if(flag_B && (~flag_C))
                idx_B = [idx_B,jj];
            elseif((~flag_B) && flag_C)
                idx_C = [idx_C,jj];
            end
        end
    end
    out_B = [out_B temp_2(idx_B)];
    out_C = [out_C temp_2(idx_C)];
    fprintf('.');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isempty(out_B)
    disp(['; zero type_B matched reads, ' num2str(toc,'%10.1f')   ' s'])
    
    NUC_B = '';
    FA_B  = '';
    RA_B  = '';
else
    NUC_B = char(out_B.SEQ);
    FA_B  = char(out_B.FA);
    RA_B  = char(out_B.RA);

end
if isempty(out_C)
    disp(['; zero type_C matched reads, ' num2str(toc,'%10.1f')   ' s'])
    
    NUC_C = '';
    FA_C = '';
    RA_C = '';
else
    NUC_C = char(out_C.SEQ);
    FA_C  = char(out_C.FA);
    RA_C  = char(out_C.RA);
end

end