Stewart Stremler wrote: > 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.
Yeah. I recall some unfriendly programs having the convention that if the <char> in \<char> _wasn't special_ then the interpretation should be a literal '\' followed by a literal <char>. Wouldn't that be nasty! I think (hope) all such programs died long ago. > >> 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. I _was_ thinking of saying you could always escape every char in a character class, just to be sure ;-) > >> 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. In regex's, I believe the first/last char postion is a longstanding convention. Now in other progams that use '-' for ranges, you are right (or sorta right) -- sometimes the meaning is <whatever> -- assuming, there is a real finite bound (I'm thinking of cut). > >> 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. :) Forgot other things too, didn't I. Still, what I wrote reflects _my_ reasoning when I [de]construct a regex. And like myu reasoning, I often have to add "oh yeah, there's another thing .." <heh>. Regards, ..jim -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
