From 02c95574afe918e33af3c6786293b7d407b3e983 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Mon, 8 Feb 2016 16:57:52 -0600 Subject: [PATCH] tpl: Add replaceRE function This commit addes a `replaceRE` template function. Regexp patterns are compiled once and cached. --- content/templates/functions.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/content/templates/functions.md b/content/templates/functions.md index 599e61bda..8637656e3 100644 --- a/content/templates/functions.md +++ b/content/templates/functions.md @@ -451,6 +451,13 @@ Replaces all occurrences of the search string with the replacement string. e.g. `{{ replace "Batman and Robin" "Robin" "Catwoman" }}` → "Batman and Catwoman" +### replaceRE +Replaces all occurrences of a regular expression with the replacement pattern. + +e.g. `{{ replaceRE "^https?://([^/]+).*" "$1" "http://gohugo.io/docs" }}` → "gohugo.io" +e.g. `{{ "http://gohugo.io/docs" | replaceRE "^https?://([^/]+).*" "$1" }}` → "gohugo.io" + + ### safeHTML Declares the provided string as a "safe" HTML document fragment so Go html/template will not filter it. It should not be used