mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'
This commit is contained in:
@@ -5,18 +5,29 @@ categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
keywords: [replace regex]
|
||||
keywords: [regex]
|
||||
signature:
|
||||
- "replaceRE PATTERN REPLACEMENT INPUT [LIMIT]"
|
||||
- "strings.ReplaceRE PATTERN REPLACEMENT INPUT [LIMIT]"
|
||||
relatedfuncs: [replace,findRE]
|
||||
aliases: []
|
||||
relatedfuncs: [findRE, FindRESubmatch, replace]
|
||||
---
|
||||
By default, the `replaceRE` function replaces all matches. You can limit the number of matches with an optional LIMIT parameter.
|
||||
By default, `replaceRE` replaces all matches. You can limit the number of matches with an optional LIMIT parameter.
|
||||
|
||||
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
|
||||
|
||||
The syntax of the regular expression is the same general syntax used by Perl, Python, and other languages. More precisely, it is the syntax accepted by [RE2] except for `\C`.
|
||||
[string literal]: https://go.dev/ref/spec#String_literals
|
||||
|
||||
This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.
|
||||
|
||||
[RE2]: https://github.com/google/re2/
|
||||
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/
|
||||
|
||||
{{% note %}}
|
||||
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
|
||||
|
||||
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
|
||||
[PCRE]: https://www.pcre.org/
|
||||
{{% /note %}}
|
||||
|
||||
This example replaces two or more consecutive hyphens with a single hyphen:
|
||||
|
||||
|
Reference in New Issue
Block a user