File tree Expand file tree Collapse file tree 1 file changed +20
-21
lines changed Expand file tree Collapse file tree 1 file changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -4,27 +4,26 @@ import (
4
4
"strings"
5
5
)
6
6
7
- func WildcardToRegexp (wildcard string ) string {
8
- replacer := strings .NewReplacer (
9
- "(" , "\\ (" ,
10
- ")" , "\\ )" ,
11
- "[" , "\\ [" ,
12
- "]" , "\\ ]" ,
13
- "{" , "\\ {" ,
14
- "}" , "\\ }" ,
15
- "<" , "\\ <" ,
16
- ">" , "\\ >" ,
17
- "^" , "\\ ^" ,
18
- "$" , "\\ $" ,
19
- "|" , "\\ |" ,
20
- "+" , "\\ +" ,
21
- "\\ " , "\\ \\ " ,
22
- "." , "\\ ." ,
23
- "?" , "." ,
24
- "*" , ".*?" ,
25
- )
26
-
27
- exp := "^" + replacer .Replace (wildcard ) + "$"
7
+ var regexpEscapeReplacer = strings .NewReplacer (
8
+ "(" , "\\ (" ,
9
+ ")" , "\\ )" ,
10
+ "[" , "\\ [" ,
11
+ "]" , "\\ ]" ,
12
+ "{" , "\\ {" ,
13
+ "}" , "\\ }" ,
14
+ "<" , "\\ <" ,
15
+ ">" , "\\ >" ,
16
+ "^" , "\\ ^" ,
17
+ "$" , "\\ $" ,
18
+ "|" , "\\ |" ,
19
+ "+" , "\\ +" ,
20
+ "\\ " , "\\ \\ " ,
21
+ "." , "\\ ." ,
22
+ "?" , "." ,
23
+ "*" , ".*?" ,
24
+ )
28
25
26
+ func WildcardToRegexp (wildcard string ) string {
27
+ exp := "^" + regexpEscapeReplacer .Replace (wildcard ) + "$"
29
28
return exp
30
29
}
You can’t perform that action at this time.
0 commit comments