MATLAB: Using regular expressions to ignore files starting with a certain set of characters

ignoreMATLABmatlab functionparseregexpregular expressionwhosworkspace

I am trying to write a function which can make decisions about variables in the Workspace based on their names The function has no inputs and no outputs, so it must make decisions based off variable names alone. I am currently identifying the variable names using regular expressions such as:
varGroup1 = whos('regexp','glob*') % varType will be a struct containing all variables that start with 'glob'
I am able to assemble regular expressions which include certain substrings (as above), but am unable to figure out how to write a regular expression which discludes a substring. For instance, if I wanted to separate my Workspace variables into variables which do and do not start with 'glob'. I can include 'glob' variables, but I don't know how to disclude 'glob' variables to get the non-glob group. So far I have tried:
locVars = whos('regexp', '(?<!(glob))*')
Alternatively, if there is a better way to do it without using regular expressions I am open to other options. P.S. 'glob' does not mean global, it's just an example substring.

Best Answer

Okay, just to make it clear to any one else reading this, that this is a bad idea:
moving on... in my experience, writing regular expressions to NOT match something is logically much more slippery to pin down. Not matching things is an elusive goal with regular expressions, and I have seen several questions on this forum where the OP says something like "but I want to not match THAT character!", and they fail to comprehend that a regular expression is like an octopus and it will happily squeeze around obstructions if it can. I have written some very large regular expressions (e.g. for parsing English language numbers) and my advice would be to avoid doing this: I think you should simply write one expression that simply matches what you need, and then use something like setdiff on the cell array itself (or negate the logical indices) to get the strings that do not match. That would be easier to write the regular expression for, and ensures that you do not miss any cases.
Don't use the regular expression feature at all: simply read all of the names (without any filtering), then use strfind, strncmp, regexp, or whatever, and then a setdiff or negation (depending on the index type). Bingo, two perfectly complementary sets. Something like this:
C = {...} % cell array of strings
X = strncmp(C,'glob',4);
notglob = C(~X);
hasglob = C(X);