Skip to content

Commit

Permalink
fix: improve ReplaceIfMatch regex
Browse files Browse the repository at this point in the history
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed Apr 10, 2023
1 parent 8a60b57 commit fd936ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit fd936ce

Please sign in to comment.