[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Special characters in patterns: what about \?
- From: David Kastrup <dak@...>
- Date: Wed, 27 Jun 2007 17:04:56 +0200
Frank Küster <email@example.com> writes:
> 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:
> function deluaficate(oldpat)
> local newpat
> newpat = string.gsub(oldpat,'([^\])%-','%1%%%-')
> print (newpat)
> return newpat
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
The backslash is already gone from the string before the pattern gets
interpreted, and ] as the first element in a set is taken literally.