lua-users home
lua-l archive

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

On Sun, Sep 18, 2011 at 8:05 AM, zhiguo zhao <> wrote:
> print(string.find(uri,'/([%-%+])/(.-)/(.*)')) work OK.
> but i think "print(string.find(uri,'/([\-\+])/(.-)/(.*)'))" should not be
> wrong.

Even if Lua string-matching supported backslashes, they would have to
be double-backslashes not single-backslashes as you have here. In Lua
5.1, a string literal '...[\-\+]...' just becomes '...[-+]...' at the
compilation stage. This specific example actually happens to works
fine, because it turns out these characters don't need to be escaped
in this context: '-' has no special meaning when it is the first
character in a character set, and '+' has no special meaning inside a
character set at all.