utf8.gsub
Client-side
Server-side
Shared
Returns a copy of the original input string with replaced matches from the pattern by the replacement value.
Important
This function may modify your input string even if no changes were made. Try it with runcode:
srun utf8.gsub(utf8.char(66376), "", "") == utf8.char(66376)
Syntax
string utf8.gsub ( string input, string pattern, mixed replace, [ int match_limit = utf8.len( input ) ] )Required Arguments
- input: A string character sequence.
- pattern: A string match pattern
- replace: A string literal OR an integer value OR a function (see examples below) OR a table ({ match = replacement })
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- match_limit (default: utf8.len( input )): An integer to limit the number of substitutions made.
Returns
- string: value
Returns a pair of values, the modified string and the integer number of substitutions made.
Code Examples
shared
This example shows how to remove color codes from a string and how to uppercase each single character in a string.
local text = "#ff0000This text is red"local colorless = utf8.gsub(text, "#%x%x%x%x%x%x", "")print(colorless) -- This text is red
print(utf8.gsub("Nice wiki!", ".", utf8.upper)) -- NICE WIKI!