主题
replace
js
_.replace([string=''], pattern, replacement)
用 replacement
替换 string
中 pattern
的匹配项。
¥Replaces matches for pattern
in string
with replacement
.
注意:此方法基于 String#replace
。
¥Note: This method is based on String#replace
.
新增于
¥Since
4.0.0
参数
¥Arguments
[string='']
(字符串):要修改的字符串。¥
[string='']
(string): The string to modify.pattern
(正则表达式|字符串):要否定的谓词。¥
pattern
(RegExp|string): The pattern to replace.replacement
(函数|字符串):最大递归深度。¥
replacement
(Function|string): The match replacement.
返回
¥Returns
(字符串):返回修改后的字符串。
¥(string): Returns the modified string.
示例
¥Example
js
_.replace('Hi Fred', 'Fred', 'Barney');
// => 'Hi Barney'