[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Special characters in patterns: what about \?
- From: David Kastrup <dak@...>
- Date: Wed, 27 Jun 2007 17:04:56 +0200
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