begin  quoting James G. Sack (jim) as of Wed, Feb 14, 2007 at 03:37:34PM -0800:
[snip]
> I'm sure jhriv will come up w/ a one-liner for you, but I just wanted to
> remark that your use of \. within character class brackets is not
> required. If vim requires it, then it's vim that's broke.
 
Vim seems to allow it, but does not seem to require it.

> The usual language is that '.' has no special meaning within brackets.
> 
> It's useful to dwell on this a bit -- spending a few minutes here makes
> regular expressions a little less intimidating.
>
> Normally the dot character stands for _any character_ so you can see
> that it wouldn't make much sense to define a character class list that
> contains such a wild card. If '.' means anything, then any other content
> is superfluous!

Indeed.

It helps to keep things consistent, however... "whenever I mean '.', I
must escape it" may not be optimal, but what it loses in efficiency, it
gains in consistency, and thus maintainability.

Keeping regex maintainable is generally difficult as it is.

> For further thought, the only specials within brackets ought to be '-'
> (for ranges) and ']' (the end-delimiter for the character class).
> Then you kinda have to add '\' to the specials so that you can write
> '\]' to mean a literal ']'. You can also use '\-' and, of course '\\'.
> By convention, putting the '-' as the first or last character in the
> brackets also means a literal '-'.

Does it? I thought it meant an unbounded list.

>                                    I suppose putting ']' as the first
> character might logically also mean a literal ']' (since otherwise you
> have an empty class -- maybe it actually works that way?. Arguably,
> using '\-', '\]' is better than remembering additional conventions, but
> I mention it so that you will recognize them when you see them.

You forgot ^ as the first character, for negation. :)

-- 
Optimization is not always desirable in all situations.
Stewart Stremler


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to