On 2/16/2011 11:17 AM, Roland Mainz wrote:
> On Wed, Feb 16, 2011 at 3:50 PM, Icarus Sparry
> <[email protected]> wrote:
>> On 2/15/2011 10:30 PM, ольга крыжановская wrote:
>>> Glenn, why does this grep line print chicken_long, despite the
>>> negation operator to filter '_long"?
>>>
>>> printf "chicken_x\nchicken_long\n" | ./arch/linux.i386/bin/grep -X
>>> 'chicken((_long)!)'
>>> chicken_x
>>> chicken_long
>> Negation often gives results that are not intuitive.
>> I suggest you use the '-b' flag if you are on an terminal that supports
>> ANSI escape sequences, in which case you will see that it matched
>> "chicken_lon" (no 'g'),
> Somehow this feels wrong.
I did say it was not intuitive (at least for most people).

> Glenn: Does ! always only match one single character, even if ! is
> precended by a bracket pair (e.g. "(foo)!") ?
>
I am not Glenn, but no.

>> and then printed out the entire line. Changing
>> the expression to 'chicken((_long)!)$' gives you the result you appear
>> to be expecting.
> Erm... can anyone explain in detail why grep -X works this way in
> detail, please ?
>
> ----
>
> Bye,
> Roland
>

This was discussed on the uwin mailing list, Glenn explained it in
    https://mailman.research.att.com/pipermail/uwin-users/2004q4/000585.html

As a very rough idea, think of any negated term as a '.*' with the
additional constraint that the thing matched by .* does not match the
term. So  chicken((_long)!) is like chicken((.*)) and this allows the
'.*' to match '_long', '_lon', '_lo', '_l', '_', or the empty string ''.
The longest string of this that does not match '_long' is '_lon'. On the
other hand chicken((_long)!)$  is like chicken((.*))$, and the $ means
that the .* is constrained to match '_long', and this is not allowed to
match.

As '.*' matches the empty string you almost always want to have
something after the negated term (usually either '$' or some literal
string).

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to