少于1分钟
将以下英文翻译为中文:
https://gohugo.io/functions/replacere/
Returns a string, replacing all occurrences of a regular expression with a replacement pattern.
replaceRE PATTERN REPLACEMENT INPUT [LIMIT]
strings.ReplaceRE PATTERN REPLACEMENT INPUT [LIMIT]
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.
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.
The RE2 syntax is a subset of that accepted by PCRE, roughly speaking, and with various caveats.
This example replaces two or more consecutive hyphens with a single hyphen:
|
|
To limit the number of replacements to one:
|
|
You can use $1
, $2
, etc. within the replacement string to insert the groups captured within the regular expression:
|
|
You can write and test your regular expression using regex101.com. Be sure to select the Go flavor before you begin.