I am writing a simple tool to allow people to label jobs on a server. The allowed characters are below. In addition to this, I want to allow emojis (any emojis).
I've referenced this stackoverflow question for the latter. But when I try to combine them, the code does not work.
Here's my function:
func SafeCharsRegex() *regexp.Regexp {
regexString := "A-Za-z0-9._~!:@,;+-"
emojiString := `[©®‼⁉™ℹ↔-↙↩↪⌨⏏⏭-⏯⏱⏲⏸-⏺Ⓜ▪▫▶◀◻◼☀-☄☎☑☘☠☢☣☦☪☮☯☸-☺♀♂♟♠♣♥♦♨♻♾⚒⚔-⚗⚙⚛⚜⚠⚧⚰⚱⛈⛏⛑⛓⛩⛰⛱⛴⛷⛸✂✈✉✏✒✔✖✝✡✳✴❄❇❣➡⤴⤵⬅-⬇〰〽㊗㊙----------]️?|[☝✌✍][️-]?|[⛹](?:[♀♂]️?|[️-](?:[♀♂]️?)?)?|[✊✋-------][-]?|❤(?:[]|️(?:[])?)?|[--]|[---]|[---]|[]|[-]|[-]|[---]|[]|[---]|[]|[-]|[--]|[--]|[-]||[---]||[]|[----]|[--]|[]|[]|[]||[]|[]|[-----](?:[♀♂]️?|[-](?:[♀♂]️?)?)?|(?:(?:⚧️?|)|️(?:(?:⚧️?|))?)?|(?:☠️?|(?:||))?|(?:⬛)?|(?:)?|(?:❄️?)?|(?:️?|️(?:️?)?)?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?|(?:)?|(?:[])?|[](?:(?:)?|(?:[])?)|[-])|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?)?|(?:(?:[⚕⚖✈]️?|❤️?(?:[]|[])|(?:)?|(?:[])?|(?:(?:)?|(?:[])?)|[-])|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[][-]|[][-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[][-]|[][-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[][-]|[][]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[][-]|[][-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[][-]|[][-]|[-]))?)?|[](?:[♀♂]️?)?|(?:)?|(?:)?|(?:️?)?|(?:(?:[⚕⚖✈]️?||[-])|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?|(?:(?:[⚕⚖✈]️?|❤️?(?:)?[-]|[-]|[-]))?)?|[⌚⌛⏩-⏬⏰⏳◽◾☔☕♈-♓♿⚓⚡⚪⚫⚽⚾⛄⛅⛎⛔⛪⛲⛳⛵⛺⛽✅✨❌❎❓-❕❗➕-➗➰➿⬛⬜⭐⭕-----------------------------------------------------]|(?:(?:[-])?|(?:[-])?|(?:[])?|(?:[-])?|(?:[-])?)?`
r := regexp.MustCompile(fmt.Sprintf("[^%s|%s]", regexString, emojiString))
return r
}
and here's how I'm using it.
s := ""
r := SafeCharsRegex()
safeString := r.ReplaceAllString(s, "")
EXPECTED BEHAVIOR: safeString == ""
ACTUAL BEHAVIOR: safeString == ""
I've tried removing the concetatenation, doing just the emoji string, etc, and nothing works. However, when I make the emojiString JUST those four emojis, it does work. So there's something with the VERY complex emoji string that's broken.
HOWEVER, when I go here - https://regex101.com/r/iCzyv2/1 - it works fine.