Allow NOT ']' to be matched with the pattern '[!]]' (prior to this
there was no way to match NOT ']').

Also do some refactoring to avoid relying on the vector
iterator always returning None after returning None for the
first time (as requested by @kballard).