mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-30 04:23:21 -05:00
f7c1b5fe1c
Updates for #7604
1.4 KiB
1.4 KiB
title | description | godocref | date | publishdate | lastmod | categories | menu | keywords | signature | workson | hugoversion | relatedfuncs | deprecated | aliases | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
replaceRE | Replaces all occurrences of a regular expression with the replacement pattern. | 2017-02-01 | 2017-02-01 | 2020-09-07 |
|
|
|
|
false |
strings.ReplaceRE
returns a copy of INPUT
, replacing all matches of the regular
expression PATTERN
with the replacement text REPLACEMENT
.
The number of replacements can be limited with an optional LIMIT
parameter.
{{ replaceRE "^https?://([^/]+).*" "$1" "http://gohugo.io/docs" }}` → "gohugo.io"
{{ "http://gohugo.io/docs" | replaceRE "^https?://([^/]+).*" "$1" }}` → "gohugo.io"
{{ replaceRE "a+b" "X" "aabbaabbab" 1 }} → "Xbaabbab"
{{% note %}} Hugo uses Go's Regular Expression package, which is the same general syntax used by Perl, Python, and other languages but with a few minor differences for those coming from a background in PCRE. For a full syntax listing, see the GitHub wiki for re2.
If you are just learning RegEx, or at least Go's flavor, you can practice pattern matching in the browser at https://regex101.com/. {{% /note %}}