深入探究Lua中的解析表达式
使用一个模式
这个例子显示了一个建立和使用模式的程序,它非常简单但很完整:
locallpeg=require"lpeg"
--matchesawordfollowedbyend-of-string p=lpeg.R"az"^1*-1
print(p:match("hello")) -->6 print(lpeg.match(p,"hello")) -->6 print(p:match("1hello")) -->nil
使用一个模式
这个例子显示了一个建立和使用模式的程序,它非常简单但很完整:
locallpeg=require"lpeg"
--matchesawordfollowedbyend-of-string p=lpeg.R"az"^1*-1
print(p:match("hello")) -->6 print(lpeg.match(p,"hello")) -->6 print(p:match("1hello")) -->nil