[Top][All Lists]

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

Re: How to use ']' in the upper bound of a range character set

From: Karl Berry
Subject: Re: How to use ']' in the upper bound of a range character set
Date: Fri, 22 May 2009 17:38:45 -0500

    So does it confirm that there is no way to use ']' is the RANGE
    character set

FWIW, I also believe it is correct that ] cannot be specified as the endpoint
of a range in a bracket expression.  This is because when ] is used in a
bracket expression, as far as I know it has to be the first character
after [, with the sole exception of ^.

That is, the only two ways to mention ] in a bracket expression and not
have it mean the end of the expr are:

[]] - matches just ]
[^]] - matches anything except ]

Therefore I see no way to be able to say something like [A-]] to mean
everything between A and ], which I gather is what you want.  It seems
the only way out is to specify the ] separately, as previously
suggested.  Assuming ASCII, []A-\\] matches the same set of characters
as the above hypothetical A-] range.

(Of course, such a range is locale-dependent in any case.)

    And are there any other characters that cannot be used inside the RANGE
    character set as either the upper or lower bound ? 

upper bound: no, ] is the only issue.

lower bound: If the bracket expression contains only a range, I don't
think it's possible to specify ^ as the lower bound, for essentially the
same reason as above.
[^-x] is interpreted as everything but - and x, not the range ^-x.

    documentation of grep

grep has a manual, and the section "Character Classes and Bracket
Expressions" discusses the syntax.  It does not explicitly talk about
these restrictions, it's only implicit in the rules.  Try running 
info grep  on the cmd line.

BTW, all the above has nothing to do with grep in particular, it's part
of regular expressions in general.


reply via email to

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