clear all

% basic usage
 a1 = 1;
 a2 = 2;
 clearvars a1;
 assert(~ismember('a1', who));
 assert(ismember('a2', who));

% globs
 a1 = 1;
 a2 = 2;
 clearvars a*;
 assert(~ismember('a1', who));
 assert(~ismember('a2', who));

% regexp
 a1 = 1;
 a2 = 2;
 aa = 3;
 clearvars -regexp a[0-9];
 assert(~ismember('a1', who));
 assert(~ismember('a2', who));
 assert(ismember('aa', who));

% regexp
 a111 = 1;
 a222 = 2;
 a333 = 3;
 clearvars -regexp ^a\d{3}$ -except a333
 assert(~ismember('a111', who));
 assert(~ismember('a222', who));
 assert(ismember('a333', who));

% except
 a1 = 1;
 a2 = 2;
 clearvars a* -except a2;
 assert(~ismember('a1', who));
 assert(ismember('a2', who));

% except regexp
 a1 = 1;
 a2 = 2;
 aa = 3;
 clearvars a* -except -regexp a[0-9];
 assert(ismember('a1', who));
 assert(ismember('a2', who));
 assert(~ismember('aa', who));

 % regexp except
 a1 = 111;
 a11 = 11;
 a111 = 1;
 clearvars -regexp a[0-9] -except a1;
 assert(ismember('a1', who));
 assert(~ismember('a11', who));
 assert(~ismember('a111', who));
 
 % regexp except regexp
 a1 = 111;
 a11 = 11;
 a111 = 1;
 clearvars -regexp a[0-9] -except -regexp a1;
 assert(ismember('a1', who));
 assert(ismember('a11', who));
 assert(ismember('a111', who));

% global
function f()
   assert(ismember('g3', who('global')));
   g1 = 1;
   g2 = 2;
   clearvars -global g*
   assert(ismember('g1', who));
   assert(ismember('g2', who));
end

 global g3 = 3;
 f();
 assert(~ismember('g3', who('global')));
