Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const emojiRegex = require('emoji-regex');
- const regex = emojiRegex();
- const string = "This string has emoji 👩 and 👩🏿 modified emoji and supermodiied emoji 💂🏾♀️";
- function stringReverse(string) {
- let match;
- const emojis = [];
- const separator = `unique_separator_${Math.random()}`;
- const reversedSeparator = [...separator].reverse().join('');
- while (match = regex.exec(string)) {
- emojis.push(emoji);
- }
- return [...string.replace(regex, separator)].reverse().join('').replace(new RegExp(reversedSeparator, 'gm'), () => emojis.pop());
- }
- console.log(string); // This string has emoji 👩 and 👩🏿 modified emoji and supermodiied emoji 💂🏾♀️
- console.log(stringReverse(string)); // 💂🏾♀️ ijome deiidomrepus dna ijome deifidom 👩🏿 dna 👩 ijome sah gnirts sihT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement