lua-users home
lua-l archive

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


On Sat, 5 Nov 2005 22:31:13 +0100
Manfred Lotz <manfred.lotz@arcor.de> wrote:

> Hi all,
> I encountered a strange problem using gsub:
> 
> Say I have function like this:
> function log(date,msg)
>    pat = "%date %str"
>    ostr = string.gsub(pat,"%%date",date)
>    ostr= string.gsub(ostr,"%%str",msg)
>    print(ostr) 
> end
> 
> Now log(os.date(),"strange string %4 is this")
> yields:
> 
> stdin:4: invalid capture index
> stack traceback:
>         [C]: in function `gsub'
>         stdin:4: in function `log'
>         stdin:1: in main chunk
>         [C]: ?
> 
> 
> What do I do wrong? 
> 

Oops, sorry. I found it in the reference manual. 

The data which gets fed into log is from a file. How can I change  e.g.
%4 into %%4 to prevent gsub from choking?




-- 
Manfred