-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.go
More file actions
29 lines (25 loc) · 854 Bytes
/
Copy pathutil.go
File metadata and controls
29 lines (25 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package gopherneo
import "regexp"
func EscapeStringForCypherRegex(in string) string {
//fmt.Printf("in: %v\n", in)
r1 := regexp.MustCompile("(\\')")
r2 := regexp.MustCompile("(\\(|\\))")
r3 := regexp.MustCompile("(&)")
r4 := regexp.MustCompile("(\\*)")
r5 := regexp.MustCompile("(\")")
r6 := regexp.MustCompile("(\\+)")
r7 := regexp.MustCompile("(\\$)")
r8 := regexp.MustCompile("(\\\\)")
// TODO test and add all remaining regex meta characters!
out := in
out = r1.ReplaceAllString(out, "\\\\$1")
out = r2.ReplaceAllString(out, "\\\\$1")
out = r3.ReplaceAllString(out, "\\\\$1")
out = r4.ReplaceAllString(out, "\\\\$1")
out = r5.ReplaceAllString(out, "\\$1")
out = r6.ReplaceAllString(out, "\\\\$1")
out = r7.ReplaceAllString(out, "\\\\$1")
out = r8.ReplaceAllString(out, "\\\\\\$1")
//fmt.Printf("out: %v\n", out)
return out
}