Syntax
local prefix, digits = text:match("^(%a+)%-(%d+)$")Examples
Luau pattern-based extraction
Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.
local function readCode(text: string): number?
local prefix, digits = text:match("^(%a+)%-(%d+)$")
if prefix ~= "ITEM" then return nil end
return tonumber(digits)
end
print(readCode("ITEM-42"))
print(readCode("BAD-42") == nil)- Output: 42, then true. Both the structure and the captured prefix must be accepted.
Best practices
- Use % escapes and avoid assuming regex alternation or lookaround exists. Check nil captures before numeric conversion.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation