diff --git a/utils/utils.go b/utils/utils.go index 1252424f69a2f7f7a628b34566e4759ca0452ff4..9bfa17700ffa38f994c85255b721b691b8dde10e 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -67,6 +67,32 @@ func ValidateEmailAddress(email string) (string, error) { return cleanEmail, nil } +func StripEmail(email string) (strippedEmail string, strippedDomain string) { + // Strip the email address from the + to the @ + // Define a regular expression pattern to match the "+" to "@" part + emailPattern := `(\+.*@)` + // Define the regular expression pattern to match the domain part after "@" + domainPattern := `@(.+)` + + // Compile the regular expression + emailRegex := regexp.MustCompile(emailPattern) + domainRegex := regexp.MustCompile(domainPattern) + + // Replace the matched part with an empty string + strippedEmail = emailRegex.ReplaceAllString(email, "@") + + // Find the first match in the email address + match := domainRegex.FindStringSubmatch(email) + + // Check if a match was found + if len(match) > 1 { + // The domain part (excluding "@") is in the first capture group (index 1) + strippedDomain = match[1] + } + + return strippedEmail, strippedDomain +} + // IsUrlStrict Returns whether a URL is valid in a strict way (Must have scheme and host) func IsUrlStrict(str string) bool { u, err := url.Parse(str)