Tuesday, June 18, 2013

Re: Dealing with empty strings in regexp.

John Little <John.B.Little@gmail.com> a écrit:
> On Tuesday, June 18, 2013 11:19:43 PM UTC+12, Paul Isambert wrote:
>
> > I.e., shouldn't it work clearly one way or the other?
>
> I don't understand this "interspersed empty substrings" way of
> looking at regexes; I suspect that it doesn't make sense some of the
> time, and is not useful, but my suspicions may obviously stem from my
> incomprehension.

The empty substrings are only a means to account for the difference
between Perl-like and Python-like languages; it is interesting only
inasmuch as it achieves that, and shouldn't be extended to understand
regexps any further. (Dirk Laurie formalizes that with open/closed
intervals here: http://lua-users.org/lists/lua-l/2013-04/msg00869.html.)

> A pattern like [ac]* on its own matches everywhere; so vim does the
> substitution everywhere. Why is that not intuitive? Anyway, as I see
> it, vim is consistent.

The issue is what "everywhere" means. Perl-like languages include
"just after a successful match", hence "(a)()b(c)()", Python-like
ones do not, hence "(a)b(c)". The presumed inconsistency in VimL is
that it includes "just after a successful match", unless we're at the
end of the string, hence "(a)()b(c)".

> Doing substitutions with a pattern that matches the empty string is
> not useful, in real editing tasks it's not what is wanted. One is
> always trying to match *something*.

The "*" operator should be banned, then!

Best,
Paul

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment