function str = procshuffnot(str) while 1 i = find(str=='~'); if isempty(i) return end str1 = str(i+1:end); [X,rest]=peeloff(str1); str1 = '~($)'; str2 = '((@)-($))'; str1 = strrep(str1,'$',X); str2 = strrep(str2,'$',X); str = strrep(str,str1,str2); end return function [chunk,rest]=peeloff(str) str = [str,'()']; x=find(str=='('); if (x(1)>1) % we can peel off a char chunk = str(1); rest = str(2:end); % keep that open paren else % it starts with a paren cnt=0; t=1; done=0; while ~done if (str(t)==')') cnt=cnt-1; elseif (str(t)=='(') cnt=cnt+1; end t=t+1; done = (~cnt+(t>length(str))); end if cnt error('unmatched parentheses in regexp'); end chunk = str(2:t-2); rest = str(t:end); end rest = rest(1:end-2); return