summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2017-06-13 22:11:05 -0400
committerGitHub <noreply@github.com>2017-06-13 22:11:05 -0400
commitfc522f1213eb96e23ea9d113591892a26f9f2ec3 (patch)
tree3a9fe080f9cd591532b5788294c13bd002246dd2 /docs
parentbc52886c7cf83bcbd4e4ae96ab4b0e2a84d527e7 (diff)
parent1fbfe779e6758d0f7e9143ea2a00ad050ab8c6aa (diff)
Merge pull request #161 from hairyhenderson/regexp-funcs
Adding regexp support
Diffstat (limited to 'docs')
-rw-r--r--docs/content/functions/regexp.md70
1 files changed, 70 insertions, 0 deletions
diff --git a/docs/content/functions/regexp.md b/docs/content/functions/regexp.md
new file mode 100644
index 00000000..c97a81a8
--- /dev/null
+++ b/docs/content/functions/regexp.md
@@ -0,0 +1,70 @@
+---
+title: regexp functions
+menu:
+ main:
+ parent: functions
+---
+
+## `regexp.Replace`
+
+Replaces matches of a regular expression with the replacement string. The syntax
+of the regular expressions accepted is [Go's `regexp` syntax](https://golang.org/pkg/regexp/syntax/#hdr-Syntax),
+and is the same general syntax used by Perl, Python, and other languages.
+
+### Usage
+
+```go
+regexp.Replace expression replacement input
+```
+```go
+input | regexp.Replace expression replacement
+```
+
+### Arguments
+
+| name | description |
+|--------|-------|
+| `expression` | The regular expression string |
+| `replacement` | The replacement string |
+| `input` | the input string to operate on |
+
+### Examples
+
+```console
+$ gomplate -i '{{ regexp.Replace "(foo)bar" "$1" "foobar"}}'
+foo
+```
+
+```console
+$ gomplate -i '{{ regexp.Replace "(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)" "${last}, ${first}" "Alan Turing"}}'
+Turing, Alan
+```
+
+## `regexp.Match`
+
+Returns `true` if a given regular expression matches a given input string.
+
+This returns a boolean which can be used in an `if` condition, for example.
+
+### Usage
+
+```go
+regexp.Match expression input
+```
+```go
+input | regexp.Match expression
+```
+
+### Arguments
+
+| name | description |
+|--------|-------|
+| `expression` | the regular expression to match |
+| `input` | the input string to test |
+
+### Examples
+
+```console
+$ gomplate -i '{{ if (.Env.USER | regexp.Match `^h`) }}username ({{.Env.USER}}) starts with h!{{end}}'
+username (hairyhenderson) starts with h!
+```