gsub

LUA

gsub

gsub (S, PAT, REPL [, N])

Returns a copy of S in which all occurrences of the pattern PAT have been replaced by a replacement string specifled by REPL. The second value returned is the total number of substitutionsmade. See §28 for the pattern matching format for PAT. The optional parameter N limits the maximum number of substitutions. For instance, when N is 1 only the flrst occurrence of PAT is replaced.

If REPL is a string, then its value is used for replacement.Any sequence of the form %n with n between 1 and 9 stands for the value of the n-th captured substring, which will be substituted in. If REPL is a function, then REPL is called every time a match occurs, with all captured substrings passed as arguments, in order. If the value returned by this function is a string, then it is used as the replacement string; otherwise, the replacement string is an empty string.