util.string.charpattern

Shared

A Lua pattern that matches exactly one valid UTF-8 character sequence


Syntax

local pattern = util.string.charpattern

This is a constant string field, not a function - it is read directly rather than called.

Value

TypeNameDescription
stringpatternLua pattern matching the byte sequence of a single UTF-8 character

Examples

Iterate over the raw byte sequence of each character
local text = "a€b"

for char in util.string.gmatch(text, util.string.charpattern) do
    core.engine.print("info", char)
end

--[[
Output:
'a'
'€'
'b'
]]
Use charpattern as a building block in a larger pattern
-- Matches one UTF-8 character followed by a digit
local pattern = util.string.charpattern.."%d"
local result = util.string.match("a5 €9", pattern)

core.engine.print("info", result) -- 'a5'

On this page