lua-users home
lua-l archive

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


--- On Tue, 5/21/13, Philipp Janda <siffiejoe@gmx.net> wrote:

> Am 21.05.2013 12:48 schröbte S.
> Fisher:
> > 
> > function escape( s )
> >    return string.gsub(s, "[][^$()%.*+-?]",
> "%%%0" )
> > end
> > 
> 
> Try:
> 
>     > =escape( "12345;:/<>%" )
>     %1%2%3%4%5%;%:%/%<%>%   
> 10
> 
> which is probably not what you wanted. So you need to put a
> few more escapes in there (at least before `%`, `.`, and
> `-`) ...

function escape( s )
  return string.gsub(s, "[][^$()%%.*+?-]", "%%%0" )
end

> =escape( "1234-5;:/<>.%" )
1234%-5;:/<>%.%%        3