You are fundamentally correct, but [^b]
will still match o
and g
in bog
-- meaning it is a successful match, even though it didn't match the whole string. [^bog]
will only match h
in hog
, d
in dog
, and nothing in bog
-- meaning it doesn't match bog
.
I think this will make more sense if you look at ^[^b]+$
. This will match 1+
non-b
characters, anchored at the beginning (^
) and end ($
) of the string. Comparing that to your initial expression of [^b]
or [^bog]
, you can see the difference. I suggest using a GUI RegEx tester (the previously linked one is my favorite), which will really help illustrate the logic.