bug-grep
[Top][All Lists]
Advanced

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

Re: [^\]] in basic regexes


From: Wacek Kusnierczyk
Subject: Re: [^\]] in basic regexes
Date: Sat, 14 Feb 2009 13:53:02 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

Andreas Schwab wrote:
> Wacek Kusnierczyk <address@hidden> writes:
>
>   
>> however, in that code the pattern was '[^\]]*' (with the idea that the
>> character ']' is a metacharacter and therefore must be escaped). 
>>     
>
> Inside bracket expressions the backslash is not special.  Thus '[^\]]'
> is a pattern that matches a non-backslash character followed by ']', and
> '[\]' does not qualify.
>   

well, the pattern either is 'one character which is neither a backslash
nor a closing bracket'  (thus, the leftmost and rightmost brackets
denote a class), then the pattern should match the opening bracket in
the data.

if, as you seem to imply, the pattern is 'a non-backslash followed by a
closing bracket', then
- the rightmost closing bracket is *outside* of any class, thus
- it is (should be) a *metacharacter*,
- and as such it *closes a class*, but
- there is no class to be closed, thus
- there pattern is *invalid*.

the rightmost bracket, if not a negated member of the same class as the
backslash, not only cannot match the closing bracket in the data
(because it is a metacharacter, not a literal bracket), but also is
unpaired.

the other examples where grep seems to be confused remain unexplained, too.

vQ




reply via email to

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