mozhi/utils/sanitize.go

15 lines
374 B
Go
Raw Normal View History

2023-08-15 16:11:02 +00:00
package utils
import "regexp"
func Sanitize(str string, strip string) string {
nonAlphanumericRegex := regexp.MustCompile(`[^a-zA-Z]+`)
nonAlphaRegex := regexp.MustCompile(`[^a-zA-Z0-9]+`)
if strip == "alpha" {
return nonAlphaRegex.ReplaceAllString(str, "")
} else if strip == "alphanumeric" {
return nonAlphanumericRegex.ReplaceAllString(str, "")
}
return ""
}