lua-users home
lua-l archive

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


Jan Schütze wrote:

I wanted to ask if there is any way to escape (fast) all
magic characters in the string one wants to replace?

I don't know if it's fast enough for you, but this function
does what you want:

Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
function plain2pat(s)
  s = string.gsub(s, "[[%%.*+?^$()-]", "%%%0")
  return (string.gsub(s, "%z", "%%z"))
end

allchars = ""
for i = 0, 255 do
  allchars = allchars .. string.char(i)
end
print(string.find(allchars, plain2pat(allchars)))
1       256

--
Aaron
http://arundelo.com

_________________________________________________________________
Interest Rates Fall Again! $430,000 Mortgage for $1,399/mo - Calculate new payment http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9632-18679&moid=7581