replace
替换字符串中的文本。
发布于 v1.7.0
参数:
string
: 要搜索和替换的字符串。pattern
: 要搜索的字符串或正则表达式模式。replacement
: 用于替换匹配模式的字符串。flags
: (可选)正则表达式标志。
返回: 具有替换值的字符串。
例子:
replace("Hello, Mars?", "Mars\?", "Earth!");
replace("One + one = 4", "one", "2", "gi");
replace('This is a string.', "(string)\.$", "new $1.");
replace(~"bar-1", '1', '2');
结果:
"Hello, Earth!";
"2 + 2 = 4";
'This is a new string.';
bar-2;