mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 08:45:38 +00:00
17 lines
409 B
Go
17 lines
409 B
Go
package stringutil
|
|
|
|
import "regexp"
|
|
|
|
var (
|
|
sanitizeIDRegex = regexp.MustCompile(`[^a-zA-Z0-9_\-\.]+`) // matches invalid characters in an ID
|
|
idRegex = regexp.MustCompile(`[a-zA-Z0-9_\-\.]*`) // matches a valid ID (including empty string)
|
|
)
|
|
|
|
func SanitizeID(id string) string {
|
|
return sanitizeIDRegex.ReplaceAllString(id, "_")
|
|
}
|
|
|
|
func ValidateID(id string) bool {
|
|
return idRegex.MatchString(id)
|
|
}
|