gnu-regexp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: list-subscriber
Subject: [Regexp] inverse matching such as [^a] not working
Date: Wed, 19 May 2004 16:57:01 +0800 (PHT)
User-agent: SquirrelMail/1.4.1-4_rh9

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



























reply via email to

[Prev in Thread] Current Thread [Next in Thread]