@@ -25,6 +25,7 @@ type CensorWordDetection struct {
25
25
KeepSuffixChar bool
26
26
SanitizeSpecialCharacters bool
27
27
TextNormalization bool
28
+ ReplaceCheckPattern string
28
29
}
29
30
30
31
// this will create a new CensorWordDetection object
@@ -36,6 +37,7 @@ func NewDetector() *CensorWordDetection {
36
37
KeepSuffixChar : false ,
37
38
SanitizeSpecialCharacters : true ,
38
39
TextNormalization : true ,
40
+ ReplaceCheckPattern : "(?i)%s" ,
39
41
}
40
42
}
41
43
@@ -109,7 +111,7 @@ func (censor *CensorWordDetection) CensorWord(word string) (string, error) {
109
111
for _ , forbiddenWord := range censor .CensorList {
110
112
111
113
// should replace incase sensitive
112
- pattern := regexp .MustCompile (fmt .Sprintf (`(?i)%s` , forbiddenWord ))
114
+ pattern := regexp .MustCompile (fmt .Sprintf (censor . ReplaceCheckPattern , forbiddenWord ))
113
115
var replacePattern , prefix , suffix string
114
116
wordLength := len (forbiddenWord )
115
117
@@ -126,6 +128,7 @@ func (censor *CensorWordDetection) CensorWord(word string) (string, error) {
126
128
"%s%s%s" , prefix , strings .Repeat (censor .CensorReplaceChar , wordLength ), suffix ,
127
129
)
128
130
word = pattern .ReplaceAllString (word , replacePattern )
131
+
129
132
}
130
133
// join the string
131
134
return word , nil
0 commit comments