[Regexp] inverse matching such as [^a] not working

[email protected]
Newsgroups gmane.comp.gnu.regexp
Message-ID <[email protected]>
Hello,

I specified a regular expression in grep that's supposed to match a string
if it does not contain a certain character but it seems the specified
regexp does not seem to work. Concretely, I would want to match any string
on the file foo  that does not contain the character `a'.

This is foo's content:

a
ab
ba
x
yay
z
bax
xac



This is how I invoked grep.

cat foo | grep -e '[^a]\+'

The output of the preceeding command is exactly the same as the content of
foo.  In other words, it matched all the lines on the file, which I
supposed made the entire expression useless.  Doesn't the preceeding grep
invocation mean "look for strings that do not contain an `a'?  I
understand that the `+' operator means to match 1 or more occurences of
the preceeding
expression.  Thus, it's not supposed to match any string that contains an
`a'.

However, if I specify this command:

cat foo | grep -e '^[^a]\+$'

the output is:

x
z

Now, this is my desired output.  But why specify `^' and `&'?  I think
both need not be specified since

cat foo | grep -e `x\+'

works fine (without specifying `^' nor `&').  The preceeding regexp outputs

x
bax
sax

The above regexp simply means "match all lines that contain an x".
THere's no need for `^' nor `&' in the preceeding regexp.

Thus, I still don't understand why

cat foo | grep -e '[^a]\+'

does not work as I intend to (i.e. match all strings that don't contain an
`a')?

Thanks so much!

Best Regards

Carlo
------
Carlo Florendo y Flora
Astra Philippines Inc.
www.astra.ph
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.