lua-users home
lua-l archive

Re: string.gsub (Lua 5.1.1)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


George Petsagourakis a écrit :
Shmuel Zeigerman <shmuz <at> actcom.co.il> writes:
Let's see another example:
 print (string.gsub ("abc123", "(.)",
 function(c)
 local n = tonumber(c)
 return n and n+1
 end))
abc234	6
It seems returning "abc234", 3 would make more sense.
Not at all... six (6) substitutions done.. thats all. thats what the dot do in
Lua's regular expressions. try %d for numbers or %a for letters.
No, 6 matches, but only 3 substitutions, the first three chars make the function return nil, so there is no substitution.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

AltStyle によって変換されたページ (->オリジナル) /