Skip to content

Commit

Permalink
Adds "Matches" support to filters
Browse files Browse the repository at this point in the history
So we can add things like:

{{test Matches .text "^My.*foobar$"}}

When adding filters to chains.
  • Loading branch information
rubiojr authored and muesli committed Apr 25, 2019
1 parent 4050332 commit bf7c407
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions templatehelper/templatehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package templatehelper

import (
"regexp"
"strings"
"text/template"
)
Expand All @@ -32,6 +33,10 @@ var (
"Left": func(values ...interface{}) string {
return values[0].(string)[:values[1].(int)]
},
"Matches": func(values ...interface{}) bool {
ok, _ := regexp.MatchString(values[1].(string), values[0].(string))
return ok
},
"Mid": func(values ...interface{}) string {
if len(values) > 2 {
return values[0].(string)[values[1].(int):values[2].(int)]
Expand Down

0 comments on commit bf7c407

Please sign in to comment.