lua-users home
lua-l archive

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


local rex = require "rex_pcre"
str = 'abc 123'
pat = '(\d+)'
nums = rex.match(str,pat)
print(nums)
-----------------------------------------------

But the result is nil :(

The reason is the backslash in the pattern: when Lua compiles '(\d+)', the backslash disappears, and PCRE can't see it. In order to obtain the correct results, one should either duplicate every backslash or use "long string" syntax.

Bottom line: use '(\\d+)' or [[(\d+)]].
--
Shmuel