Wednesday, May 4, 2011

Vim's regex dialect [Was: Help me please ^^]

On Wed, May 04, 2011 at 10:00:40AM -0400, Charles Campbell wrote:
> There's probably a history of regular expressions somewhere; ed
> definitely preceded (the original) vi, and I think sed did, too. Awk
> followed in sed's "footsteps", and Perl came after vi. Vim follows
> vi's reg-ex (with extensions) handling. Anyway, I don't think the
> various programs' reg-ex styles are going to merge because that would
> invalidate a lot of scripts, so claiming that "X's style is better
> than Y's style" isn't going anywhere. IMHO Vim did it the right way
> -- that is, it extended earlier reg-ex handling, not changed it (like
> Perl did).

Regex uniformity across unix tools is valuable beyond measure, because
we then don't fumble and stumble unproductively when moving between them.
O'Reilly's "Mastering Regular Expressions" mentions that "POSIX
standardized the workings of over 70 programs, including traditional
regex-wielding tools such as awk, ed, egrep, expr, grep, and sed."

OK, grep defaults to BRE (basic regular expression), while egrep and awk
default to ERE (extended regular expression), but standards don't
preclude all choice. IME, custom extensions may bring benefits, but that
needs to be on a common RE base, if the tool is to deliver greatest
utility, OOTB.

For some time I've intended to check how close vim wanders to posix EREs
when its regexes are prefixed with \v, but for the moment it's good
enough that it mostly works when thinking in EREs. (To whatever extent
vim can be set to be posix compliant, I agree that "Vim did it the right
way".)

Yes, perlisms are "more powerful", but I'd still only use the ERE
capability, where possible, if I ever were to use perl, because that's
the common base.

Erik

--
In general, they do what you want, unless you want consistency.
- Larry Wall in the perl man page

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: