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, PUC-Rio
function plain2pat(s)
  s = string.gsub(s, "[[%%.*+?^$()-]", "%%%0")
  return (string.gsub(s, "%z", "%%z"))

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


Interest Rates Fall Again! $430,000 Mortgage for $1,399/mo - Calculate new payment