Utf8.match
From Multi Theft Auto: Wiki
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. For more information on optional arguments, see optional arguments.
- index: An integer representing the beginning position for the pattern matching
Returns
Returns a sequence of string matches from the input string, nil otherwise.
Example
Click to collapse [-]
ServerThis 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