Exclude certain characters

By using brackets, you can limit the valid characters in a format specification.

Examples

This specification... ...means this
N[1357] One digit: 1, 3, 5, or 7.
N[1357](3) Three digits, each of which can be 1, 3, 5, or 7.
X[#]N[4] A "#" character and then 4.
X[AaBb] One character: A, a, B, or b.

An exclusion symbol (^) is available to disallow invalid characters. In order to disallow characters, the "^" symbol must be in the first position of the string. All characters following the "^" are disallowed.

If the "^" is not at the beginning of the string, then "^" is a valid character.

When using the exclusion symbol in combination with a hyphen (-), the hyphen must be the last character before the closing bracket (]).

Examples

A[^QVZ] Any letter of the alphabet except Q, V, or Z.
X[^*](2-4) Two to four characters; not an asterisk.
X[ #<^] One of three possible characters: "#", "<", or "^".
X[ #<^135] One of six possible characters: "#", "<", "^", 1, 3, or 5.
X[ #<^^] An invalid specification.
X[^_*#-](3-25) Three to twenty five characters but not "_", "*", "#", or "-".
X[^_-*#](3-25) An invalid specification, because the hyphen (-) is not the last character before the closing bracket.