fix: improve ReplaceIfMatch regex

Signed-off-by: Matthis Holleville <matthish29@gmail.com>
This commit is contained in:
Matthis Holleville
2023-04-10 23:36:43 +02:00
parent 8a60b57940
commit fd936ceaf7

View File

@@ -110,9 +110,9 @@ func MaskString(input string) string {
}
func ReplaceIfMatch(text string, pattern string, replacement string) string {
re := regexp.MustCompile(fmt.Sprintf(`%s(\b\s)`, pattern))
re := regexp.MustCompile(fmt.Sprintf(`%s(\b)`, pattern))
if re.MatchString(text) {
text = re.ReplaceAllString(text, replacement+" ")
text = re.ReplaceAllString(text, replacement)
}
return text
}