[luatex] [OT] The consumption of an input string.
Paul Isambert
zappathustra at free.fr
Mon Jun 17 14:43:43 CEST 2013
Hello all,
This is not really a LuaTeX question, but I ask it here anyway since a
lot of knowledgeable people read this list.
I’ve been surprised to discover that
print(string.gsub('abc', '.*', '(%0)'))
returns
(abc)()
(similarly, “string.gmatch('abc', '.*')” returns two matches). I’d
expect
(abc)
since the string is completely consumed after the first match and
there’s no reason to try matching any further. I thought it was a Lua
quirk but then in Ruby
puts 'abc'.gsub(/.*/, '(\0)')
returns the same thing. On the other hand, “(abc)” is returned as
expected (by me) with
echo substitute('abc', '.*', '(\0)', 'g')
in Vim script and
import re
print re.sub(re.compile('(.*)'), '(\\1)', 'abc')
in Python and
echo "abc" | sed 's/.*/(\0)/g'
with sed (I’m not familiar with Python and sed, so the last two codes
are only tentative).
Now, my knowledge in programming languages being what it is, I might
be confused by something obvious; if anybody could shed some light,
I’d be grateful.
Best,
Paul
More information about the luatex
mailing list