Syntax
local name, digits = text:match("^(%a+):(%d+)$")Examples
Lua pattern captures
Run with standalone Lua 5.4: lua example.lua. These scripts target Lua 5.4 rather than Roblox Luau.
local input = "level:12"
local label, digits = input:match("^(%a+):(%d+)$")
if label then print(label .. "=" .. (tonumber(digits) + 1)) end- Output: level=13. The captures return label and digit strings; malformed input returns nil.
Best practices
- Anchor validation patterns and convert captured numbers explicitly. Lua uses % escapes rather than regex backslash escapes.
Runtime & versions
Lua interpreter or a host application. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Lua reference manuals