diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2020-05-06 22:17:19 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2020-05-06 22:17:19 -0400 |
| commit | f607561e026d28c618a8b11d149fb99453c5d46a (patch) | |
| tree | 8eeec770e15109b1287ded995be1b58d549f5d94 /regexp | |
| parent | cdc84127a939743d9f6bf879c52a38c6d279ad6d (diff) | |
Add function regexp.QuoteMeta
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'regexp')
| -rw-r--r-- | regexp/regexp.go | 5 | ||||
| -rw-r--r-- | regexp/regexp_test.go | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/regexp/regexp.go b/regexp/regexp.go index 86c7d601..e2d1df1c 100644 --- a/regexp/regexp.go +++ b/regexp/regexp.go @@ -27,6 +27,11 @@ func Match(expression, input string) bool { return re.MatchString(input) } +// QuoteMeta - +func QuoteMeta(input string) string { + return stdre.QuoteMeta(input) +} + // Replace - func Replace(expression, replacement, input string) string { re := stdre.MustCompile(expression) diff --git a/regexp/regexp_test.go b/regexp/regexp_test.go index 89f6cb86..1a6bb858 100644 --- a/regexp/regexp_test.go +++ b/regexp/regexp_test.go @@ -107,3 +107,7 @@ func TestSplit(t *testing.T) { assert.EqualValues(t, d.expected, f) } } + +func TestQuoteMeta(t *testing.T) { + assert.Equal(t, `foo\{\(\\`, QuoteMeta(`foo{(\`)) +} |
