Lua 的正则跟 Posix 标准正则不兼容,比如lua 里%d 代表数字,而标准正则是\d,
还有%是代表转义,而标准的语法是\作转义符号,下面的代码会诡异,竟然没有匹配上:
#!/usr/local/bin/lua
resize = '96*96,180*180';
format = "^(%d+%*%d+)(,%d+%*%d+)*$";
if (not string.find(resize, format)) then
print 'wrong!'
else
print 'ok!'
end
输出结果是 wrong!
请大神指点!!
Lua 的
+
、*
、?
等只是针对字符的,不能像其它语言一样用于()
分组。如果需要 POSIX 正则,可以用 Lrexlib 之类。