0Pricing
Lua Academy · Lesson

Captures and string.match

Extract captured groups from strings using string.match and () captures.

What Are Captures?

Captures are parenthesized sub-patterns in Lua patterns. They extract sub-strings from the matched text.

string.match with Captures

When a pattern contains captures, string.match returns the captured substrings instead of the whole match.

local date = "2025-01-15"
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
print(y, m, d)  -- 2025  01  15

All lessons in this course

  1. Lua Pattern Syntax
  2. Captures and string.match
  3. string.gmatch for Tokenization
  4. string.gsub for Transformations
← Back to Lua Academy