[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Special characters in patterns: what about \?
- From: Frank Küster <frank@...>
- Date: Wed, 27 Jun 2007 16:59:08 +0200
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)