I have a string in JavaScript like so:
var string = " Hello world!"; // Length of emoji at end: 2 characters ("".length = 2)
Or:
var string = " Hello world! "; // Length of emoji at end: 8 characters ("".length = 8)
Or a string without an emoji:
var string = " Hello world!"; // No emoji at end
I need to find the out following:
- Is there an emoji at the end of the string?
- How many characters does it consist of?
I came as far as detecting two-character emojis with the following code:
var emoji = new RegExp('\\p{Extended_Pictographic}', 'u');
var isEmoji = emoji.test(string.slice(-2)); // true for the first string
However, this obviously does not detect the length (e.g. = 8). If anyone has experience with emojis in JavaScript and could point me in the right direction it would be very much appreciated.