Using GNU Regex

I'm just learning Regex and while testing my understanding I received some unexpected results.

I created example.txt with the text "abcddd". Running the command

grep --color '[^abc]d' example.txt

I received the results:

"abcddd"

with the first and second letter d highlighted in red.

So based on this return my statement meant- search the file example.txt for a string where the first character is not a,b, or c that is followed by the character d and highlight the found characters.

What is confusing is that in my LPIC guide the character ^ represents the start of line. In practice it seems to represent "exclude the following characters". Is there a difference in using it inside the brackets vs. outside brackets?

---------- Post updated at 01:44 PM ---------- Previous update was at 01:25 PM ----------

Apologize I actually found the answer in after reading more carefully.

The use of carat "^a" specifies that the line start with the character "a".

The use of ^a is context sensitive. If ^a appears at the start of an RE, it matches a input whose first character is a , but if ^ is the first character in a bracket expression (such as [^abc] , it makes the bracket expression a non-matching bracket expression (in this case matching any single character that is not a , not b , and not c ). So, in your original command, the first place in the string abcddd that matched the BRE [^abc]d was the dd after the c . In this case the first d is a character that was not a , b , or c and the second d matches the d in the BRE after the non-matching bracket expression. To get what you originally requested, I assume that you came up with something like:

grep --color '^[^abc]d' example.txt

where the first circumflex in the BRE is an anchor and the 2nd circumflex identifies the bracket expression as a non-matching bracket expression.