According to this answer and the documentation for StringExpression, Except
can only be used in StringExpression
for classes of characters or positions in strings. The referenced answer suggests using StringFreeQ in place of StringMatchQ. However, sometimes, this is not possible, if the pattern is one of many being passed to a function, like in the following situation
patt1 = WordCharacter..;
patt2 = "pattern";
patt3 = (*Some complicated StringExpression*);
... (*more patterns*)
pattn = (*Everything except patt3*)
f[patt_, str_] := If[StringMatchQ[str, patt], (*stuff*), (*other stuff*)]
One possibility is to use
pattn = x: __ /; !StringMatchQ[x, patt3]
This seems repetitive and it could get verbose if repeated, but isn't too bad. However, my intuition is that there should be a better way. Is there?