The use of "[^ ]" to mean "any character except those in the list", is described here.
Read on to find out what you have to do to include any of the characters "[", "]", "-" or "^" in your list:
For example, suppose you wanted to recognise the arithmetic operators: "+", "-", "*" or "/". If you write:
[+-*/]what you will actually get is: any of the characters between "+" and "*", or a "/".
[-+*/]or:
[+*/-]
[#+[*]as, between "[" and "]", another "[" doesn't have a special meaning.
However, if we try to use "]" like this:
[#+]*]then egrep thinks it has found the end of the list at the first "]", and can get very confused by the following characters (i.e. "*" and "]" in this example). Instead, we have to put the "]" at the start of the list, like this:
[]#+*]The authors of egrep assume that no-one would be stupid enough to have a completely empty list (i.e. "[]") and take the first "]" as an ordinary character, and look for another "]" to terminate the list properly.
For example, suppose you wanted to recognise the special characters: "^" or "&" or "*". If you write:
[^&*]what you will actually get is: any character except "&" or "*"
[&^*]or:
[&*^]