Added regex details to replace() docs

This commit is contained in:
Chris Arcand 2019-07-11 11:29:41 -05:00
parent 5ac920223f
commit 22385c3198
1 changed files with 10 additions and 0 deletions

View File

@ -20,9 +20,19 @@ each occurrence with a given replacement string.
replace(string, substring, replacement) replace(string, substring, replacement)
``` ```
If `substring` is wrapped in forward slashes, it is treated as a regular
expression; the syntax conforms to the [re2 regular expression
syntax](https://github.com/google/re2/wiki/Syntax) syntax. If using a regular
expression for the substring argument, the `replacement` string can incorporate
captured strings from the input by using an `$n` sequence, where `n` is the
index or name of a capture group.
## Examples ## Examples
``` ```
> replace("1 + 2 + 3", "+", "-") > replace("1 + 2 + 3", "+", "-")
1 - 2 - 3 1 - 2 - 3
> replace("hello world", "/w.*d/", "everybody")
hello everybody
``` ```