I am trying to write a regular expression (for the JavaScript regex engine) that I can use to find and replace text for emoji names in colons. Like in Slack or Discord when typing :smiley-face:, and it replaces it when sending a chat. I only target text nodes, so I don't need to worry about another html inside the text.
Is it possible to write a regular expression that could meet all of the following rules? (text highlighted in monoscopic blocks = regular expressions)
:any-non-whitespace:
:text1:sample2:
:@(1@#$@SD: :s:
:nospace::inbetween:because in the middle there are 2 colons
:nospace:average:nospace:
I start with something like this, but it's incomplete
/:(?!:)\S+:/gim
I try to think of all the special cases that may occur in this case. Maybe I'm overdoing it.
There are a lot of Twitch emotions there, so I cannot use the unicode characters from emoji. The regular expression will find matches and replace with tags
source
share