Re: LuaJIT throws the exception "invalid escape sequence near [^%w' that Lua5.1 does not

  • From: Crew <carborundumcrew@xxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 22 May 2017 06:05:01 -0700

On 2017-05-22 05:52, JS wrote:

On 22.05.2017 15:45, Crew wrote:
Hi folks,

I am trying to convert to using LuaJIT from Lua5.1 and hit this error in
one of the Lua modules.

As I stated in the subject above LuaJIT is throwing an invalid escape
sequence exception on a sequence that Lua5.1 accepts.

The string that causes the problem is '[^%w\-_ ]'.

Is this a known problem? Is there a workaround apart from deleting the
backslash?


Hi, it should be %-, not \-. Backslash should only be used for
characters like \t.

Thank you for that. According to this posting http://lua-users.org/lists/lua-l/2011-09/msg00296.html

It would appear LuaJIT is simply being stricter about escape sequences
in strings. in the regular Lua interpreter, "\-" translates into "\\-"
because "\-" is not a valid escape sequence. In LuaJIT, you get an
actual error...

it seems I should convert them to \\- rather than %-.

Not sure which approach to take.

--
Infogalactic: the planetary knowledge core

Other related posts: