utf8.match | Multi Theft Auto: Wiki Skip to content

utf8.match

Client-side
Server-side
Shared

Extract substrings by matching patterns in the input string. This function can be used to extract specific information from a string.

Syntax

string,​ ... utf8.match ( string input, string pattern, [ int index = 1 ] )
Required Arguments
  • input: A string character sequence.
  • pattern: A string match pattern.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • index (default: 1): An integer representing the beginning position for the pattern matching.

Returns

  • string: value 1
  • ...: values

Returns a sequence of string matches from the input string, nil otherwise.

Code Examples

shared

This example shows how to extract values from an input string by using a pattern to match the value parts.

local input = "Level: 5, Rank: General, 128.42 points"
local level, rank, points = utf8.match(input, "Level: (%d+), Rank: (.-), (%d+.?%d*) points")
level, points = tonumber(level), tonumber(points)
print(level, rank, points) -- 5, General, 128.42