Skip to content

Commit

Permalink
Support for replace with regexp
Browse files Browse the repository at this point in the history
This PR addresses issues schibsted#346 and schibsted#347.
Added documentation.
  • Loading branch information
Carlo Dapor committed May 26, 2024
1 parent 22aaa35 commit 1eebe41
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,24 @@ replace("abc def ghi", "[a-z]", "x") => "xxx xxx xxx"
replace("abc def ghi", "[a-z]+", "x") => "x x x"
```

### _replace-regexp(value, regexp, out) -> string_

Replaces the string in `value` that matches `regexp` with `out`.
If `value` is not a string, it's converted to a string, except
if it is `null`. `regexp` and `out` must be strings.

It is an error for `regexp` ever to match an empty string.

If the `regexp` does not match the input,`out` corresponds to `value`.

Examples:

```
replace-regexp("2019-12-31", "([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])", "$2/$3/$1") => "12/31/2019"
replace-regexp("2019-12-31", "(?<year>[0-9][0-9][0-9][0-9])-(?<month>[0-9][0-9])-(?<day>[0-9][0-9])", "$3.$2.$1") => "31.12.2019"
replace-regexp("2019-12-31", "([a-z]+)", "$1") => "2019-12-31"
```

### _trim(string) -> string_

Removes leading and trailing whitespace in the input string. If the
Expand Down

0 comments on commit 1eebe41

Please sign in to comment.