lua-users home
lua-l archive

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


On Thu, Jul 21, 2011 at 12:08:54PM +0200, steve donovan wrote:
> On Thu, Jul 21, 2011 at 12:05 PM, Dirk Laurie <dpl@sun.ac.za> wrote:
> > Quick workaround: devise a pattern that matches `item` and no other
> > substring of `str`.
> 
> Or just use something like this to un-magic the string?
> 
> function.escape(s)
>     return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1'))
> end
> 
> (I hope it is correct, since it is from Penlight)
> 
> steve d.
> 
After changing `function.escape` to `function escape`, it works
on my example.

Instead of a pattern item `%r`, a more orthogonal idea might be
that `string.format` should have a format item `%Q`, doing the same
as your function `escape`. 

Dirk