[Top][All Lists]

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

Re: Grep - possible bug with escaped brackets

From: John.Cowan
Subject: Re: Grep - possible bug with escaped brackets
Date: Mon, 6 Jun 2005 07:22:40 -0400
User-agent: Mutt/

Ayval Ron scripsit:

> address@hidden root]# echo "try[" | grep -e "try[\[]"
> try[
> (matches)
> address@hidden root]# echo "try]" | grep -e "try[\]]"
> address@hidden root]#
> (no match)
> Seems that escaping the closing bracket the should be matched does not
> work, and that it is treated the same as a non-escaped bracket.

Character classes within regular expressions do not implement \-escaping,
so [\[] matches either a \ or an [, and [\]] matches a \ followed by a ].
Traditionally, the only magic characters inside a character class were
^ (negate), ] (close), and - (range); they can be made non-magic by
making ^ non-initial, ] initial, and - either initial or final.

Note that ] outside a character class is not magic at all.

What is the sound of Perl?  Is it not the       John Cowan
sound of a [Ww]all that people have stopped     address@hidden
banging their head against?  --Larry            http://www.ccil.org/~cowan

reply via email to

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