[luatex] [OT] The consumption of an input string.

luigi scarso luigi.scarso at gmail.com
Tue Jun 18 11:39:00 CEST 2013

On Mon, Jun 17, 2013 at 11:51 PM, Paul Isambert <zappathustra at free.fr>wrote:

> luigi scarso <luigi.scarso at gmail.com> a écrit:
> > On Mon, Jun 17, 2013 at 7:24 PM, Paul Isambert <zappathustra at free.fr>
> wrote:
> >
> > >
> > > still prints “(abc)()” (the “$” is included to make it comparable to
> > > “.*”), whereas the equivalent
> > >
> > >     echo substitute('abc', '.\{-}$', '(\0)', 'g')
> > >
> > I don't know vim,
> Bad Luigi.
> >                   but does zero-width
> > http://vimdoc.sourceforge.net/htmldoc/pattern.html
> >
> http://davidchuprogramming.blogspot.it/2012/04/vim-tip-not-containing-pattern-2.html
> > have some influence ?
> I don’t think so. As expressed in the discussion pointed to by Dirk,
> the difference seems to be one of implementation not of semantic
> difference between similar operators (although it actually makes a
> difference). Dirk even formalized all that (in the same discussion),
> and if I understood correctly the punchline is (as long as you agree
> with Dirk, as I do): substrings should be closed intervals! Which
> makes a nice motto, too bad Lua doesn’t endorse it.
> Thanks,
> Paul
> reading
I can say that agree, but coming from perl I also say that I find Lua
natural for me.
When I have an unexpected  behaviour I think then pattern with ϵ, the zero
width string,
eg  abc as
and in this way also your prev. example looks reasonable (greedy and global
match considered).

print((string.gsub(";a;", "a*", "ITEM")))

target string is
pattern  is a* = ϵ|a+
replacement is ITEM
If we rewrite the target as
we have
ϵ=target[1] match  => ITEM
;=target[2] no match => ;
ϵ;target[3] match => ITEM
aϵ=target[4] & target[5] match (greedy) => ITEM
;=target[6] no match => ;
ϵ=target[7]  match => ITEM

Given that there is a pcre lib I tend to consider perl as reference --- but
I also know that many find regex complicate to understand/implement,
so I don't  complain when Lua says that
its regex are not perl or posix compatible because it wants to maintain the
size of the code low.

How do you reproduce the same behaviour of Lua string.gsub("abc"...
with Vim ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/luatex/attachments/20130618/cd57a8a4/attachment-0001.html>

More information about the luatex mailing list