[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Special characters in patterns: what about \?
- From: Jools <joolski@...>
- Date: Wed, 27 Jun 2007 16:12:28 +0100
I think the problem is that you need to escape the \ with another \.
([^\])%-','%1%%%- needs to be ([^\\])%-','%1%%%-
You can see the logic for this in llex.c function read_string().
Cheers,
--Jools
On 6/27/07, Frank Küster <frank@kuesterei.ch> wrote:
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
deluaficate('lm-hist')
***********************
(this is supposed to be the first step in using a user-supplied
filename, which might contain a hyphen, as a pattern for
string.match(); I want to give power users full access to lua patterns,
therefore '\-' should not be replaced).
Surprisingly, this gives:
$ ./deluaficate
/usr/bin/lua: ./deluaficate:5: malformed pattern (missing ']')
stack traceback:
[C]: in function 'gsub'
./deluaficate:5: in function 'deluaficate'
./deluaficate:10: in main chunk
[C]: ?
~$ lua -v
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
What am I missing?
Regards, Frank
--
Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)