lua-users home
lua-l archive

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


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 `-`) ...

Philipp


p.s.: Maybe we should have a string.escape() function in Lua's standard library (or at least an example in the ref manual ready for copy & paste) ...