String.replace_all
String.replace_all
功能
替换字符串中的全部匹配内容。
语法
string.replace_all(from, to)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| from | String 或 Regex | 是 | 无 | 要替换的内容。 |
| to | String | 否 | 空字符串 | 替换后的内容。 |
返回值
| 类型 | 说明 |
|---|---|
| String | 替换后的新字符串。 |
代码示例
result = 'a-a-a'.replace_all('a', 'b') print result
注意事项
- 与 replace 不同,replace_all 会替换全部匹配。