Ruby, Lua, R and Awk methods for performing a global pattern substitution.
Ruby
The String#gsub
method replaces all occurrences of a pattern (a regex or a plain string) with another string or the result of a block. gsub
returns a copy of the original string with the replacements applied, gsub!
performs that replacement in-place.
Lua
If used simply, it will replace all instances of provided lua-pattern with the replacement passed as argument. Instead, if the replacement is a function and not a string, the function receives all matched instances of the pattern as arguments. The string value; if returned, by the function is then substituted back in original string.
R
The function gsub
replaces all occurrences of a pattern (a regex or a plain string) with another string or the result of a block. The function returns a new object; the original object is not modified. The function is vectorized and hence can be applied to vectors of strings too.
Awk
The function gsub(p, s [, t])
replaces all occurrences of a pattern p
(a regex or a plain string) with another string s
, either in the named target variable, t
or in $0
if no target is given.