Andreas Schwab wrote: > Wacek Kusnierczyk <[email protected]> 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
