Like pattern charlists ([...]) do not work the way the mask "*[!~[?][#][*]]*" assumes. The problem is the structure of the character list, not the negation logic.
Key rules from the docs:
-
[charlist] means “any single character in charlist”.
-
[!charlist] means “any single character not in charlist”.
- Inside a single pair of brackets,
charlist is just a flat list/range of characters; you cannot nest further [...] groups inside it.
- To match special characters
?, #, *, [ literally, they must be inside a single [...] group, not in separate bracketed groups.
From the context:
-
? matches any single character.
-
* matches zero or more characters.
-
# matches any single digit.
-
[charlist] matches any single character in charlist.
-
[!charlist] matches any single character not in charlist.
Your constant:
Const con403WldCrdMsk As String = "*[!~[?][#][*]]*"
Inside the outer brackets, the charlist is:
! ~ [ ? ] [ # ] [ * ] ]
That is not a valid single character list. The nested [?], [#], [*] are not treated as separate “sub-lists”; they are just literal bracket characters and other characters in one malformed list. This causes the pattern not to mean “not any of ~ ? # * [” as intended, and the result is that the Like comparison does not behave as expected, so all of tests 1–4 return False.
To express “any character that is not one of the wildcard characters ~, ?, #, *, [” the charlist must be written as a single bracket group with those characters inside it:
Const con403WldCrdMsk As String = "*[!~?#[*]*"
Explanation of that list:
-
! at the start: negation (match any character not in the list).
-
~ ? # * [ are the literal characters being excluded.
-
[ is included literally because it is inside the charlist; per the docs, special characters ?, #, *, [ match themselves when enclosed in brackets.
So the corrected mask is:
Const con403WldCrdMsk As String = "*[!~?#[*]*"
With that pattern, a, b, d, e will return True only if they contain at least one character that is not ~, ?, #, *, [.
The second constant
Const con403FndTxtMsk As String = "*[!A-Za-z0-9 ]*"
is syntactically correct: a single charlist with a negated range A-Z, a-z, 0-9, and space. That is why tests 5–8 behave as expected.
References: