aboutsummaryrefslogtreecommitdiff
path: root/spec/util.go
blob: 56e91211739899e6b30ed7639eb74f6949ec2f4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package spec

import "strings"

var rep = strings.NewReplacer(
	`.`, `\.`,
	`*`, `\*`,
	`+`, `\+`,
	`?`, `\?`,
	`|`, `\|`,
	`(`, `\(`,
	`)`, `\)`,
	`[`, `\[`,
	`\`, `\\`,
)

// EscapePattern escapes the special characters.
// For example, EscapePattern(`+`) returns `\+`.
func EscapePattern(s string) string {
	return rep.Replace(s)
}