Utf8.match
Jump to navigation
Jump to search
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
See Also
- utf8.byte
- utf8.char
- utf8.charpos
- utf8.escape
- utf8.find
- utf8.fold
- utf8.gmatch
- utf8.gsub
- utf8.insert
- utf8.len
- utf8.lower
- utf8.match
- utf8.ncasecmp
- utf8.next
- utf8.remove
- utf8.reverse
- utf8.sub
- utf8.title
- utf8.upper
- utf8.width
- utf8.widthindex