lang: funcs: Add regexp package and match function

This adds a simple regexp match function. This will be useful for
regexp based name classification, if you're into that sort of thing.
This commit is contained in:
James Shubin
2019-04-16 21:42:32 -04:00
parent eba45e6207
commit fc3baa28d6
5 changed files with 160 additions and 0 deletions

10
examples/lang/regexp0.mcl Normal file
View File

@@ -0,0 +1,10 @@
import "fmt"
import "regexp"
# test with:
# ./mgmt run --hostname foo.example.com --tmp-prefix lang --lang examples/lang/regexp0.mcl
# ./mgmt run --hostname db1.example.com --tmp-prefix lang --lang examples/lang/regexp0.mcl
print "regexp" {
# TODO: add a heredoc string to avoid needing to escape the \ chars
msg => fmt.printf("match: %t", regexp.match("^db\\d+\\.example\\.com$", $hostname)),
}