After TONS of research, I have found how to parse emoji in realtime using the Twemoji library.
Now, I need to figure out how to identify if there's emoji within some text, grab the position of that emoji and execute the parsing function.
Some example text can be
It is a great day ๐.
Need to find the ๐ within the whole string and use the following function to get its hex code, return the surrogate pairs and parse with the Twemoji library.
function entityForSymbolInContainer(selector) {
var code = data.message.body.codePointAt(0);
var codeHex = code.toString(16);
while (codeHex.length < 4) {
codeHex = "0" + codeHex;
}
return codeHex;
}
// Get emoji hex code
var emoji = entityForSymbolInContainer(data.message.body);
// For given an HEX codepoint, returns UTF16 surrogate pairs
var emoji = twemoji.convert.fromCodePoint(emoji);
// Given a generic string, it will replace all emoji with an <img> tag
var emoji = twemoji.parse(emoji);
I am using the following check to see if there's emoji within the text. Problem is that for a simple grinning face (๐) it doesn't alert me. However, if I type in the "shirt and tie" (๐) it will alert me to that.
var string = "It is a great day ๐.";
var emojiRegex = /([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g;
if (string.match(emojiRegex)) {
alert("emoji found");
}
Please help on the issue of the regex not picking up the emoji. After that, I should be able to just find that within the string.
Thank you!
Swift 5 Scalars have isEmoji and isEmojiPresentation properties that will help to find emoji in particular String. isEmoji - Boolean value indicating whether the scalar has an emoji presentation, whether or not it is the default.
To check if a string contains emojis in JavaScript, we can use a regex expression to match a range of Unicode specific to emojis.
Does regex work with Emojis? emoji-regex offers a regular expression to match all emoji symbols and sequences (including textual representations of emoji) as per the Unicode Standard. It's based on emoji-test-regex-pattern, which generates (at build time) the regular expression pattern based on the Unicode Standard.
Nowadays with ES2018 we can use Unicode Property Escapes in a regex match:
\p{โฆ}
For simple emojis it would be:
"Be kind ๐, smile".match(/\p{Emoji}+/gu)
For emojis including glyphs glued with ZERO WIDTH JOINER like ๐จโ๐ฉโ๐งโ๐ฆ it can be:
"My Family ๐จโ๐ฉโ๐งโ๐ฆ".match(/[\p{Emoji}\u200d]+/gu)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With