lua-users home
lua-l archive

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


Frank Küster <frank@kuesterei.ch> writes:

> Hi,
>
> is this a bug or am I misunderstanding anything?  According to the
> reference manual, 
>
> ,----
> | x: (where x is not one of the magic characters ^$()%.[]*+-?)
> |    represents the character x itself.
> `----
>
> so \ is not mentioned as a special character.  However, in the "not set"
> pattern [^\] it seems to "escape" the closing square bracket:
>
> ***********************
> #!/usr/bin/lua
>
> function deluaficate(oldpat)
>    local newpat
>    newpat = string.gsub(oldpat,'([^\])%-','%1%%%-')
>    print (newpat)
>    return newpat
> end

dak@lisa:~$ lua
Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> print('([^\])%-')
([^])%-
> 
dak@lisa:~$ 

The backslash is already gone from the string before the pattern gets
interpreted, and ] as the first element in a set is taken literally.

-- 
David Kastrup