From 25fa43c1d3db7a839df4495f6f90873c4d797a74 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 25 Sep 2022 09:25:53 +0200 Subject: [PATCH] feat(template): add regex support resolves #2823 --- src/template/func_map.go | 2 ++ src/template/regex.go | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/template/regex.go diff --git a/src/template/func_map.go b/src/template/func_map.go index 09604fc5..7b9ab496 100644 --- a/src/template/func_map.go +++ b/src/template/func_map.go @@ -12,6 +12,8 @@ func funcMap() template.FuncMap { "url": url, "path": path, "glob": glob, + "matchP": matchP, + "replaceP": replaceP, } for key, fun := range sprig.TxtFuncMap() { if _, ok := funcMap[key]; !ok { diff --git a/src/template/regex.go b/src/template/regex.go new file mode 100644 index 00000000..bdaf77ec --- /dev/null +++ b/src/template/regex.go @@ -0,0 +1,11 @@ +package template + +import "oh-my-posh/regex" + +func matchP(pattern, text string) bool { + return regex.MatchString(pattern, text) +} + +func replaceP(pattern, text, replaceText string) string { + return regex.ReplaceAllString(pattern, text, replaceText) +}