I'm using the following function to replace emojis in a string and is working great:
function doEmoji(s){
var ranges = [
'\ud83c[\udf00-\udfff]', // U+1F300 to U+1F3FF
'\ud83d[\udc00-\ude4f]', // U+1F400 to U+1F64F
'\ud83d[\ude80-\udeff]' // U+1F680 to U+1F6FF
];
var x = s.toString(16).replace(new RegExp(ranges.join('|'), 'g'),' whatever ');
return x;
};
Now I want to check if that string only contains emojis or space characters. The reason why I want to do this is because I want to replace emojis only if no other characters are present(except space).
Some examples:
Hello how are you? πΌ //do nothing
π¨βπ©βπ§ // replace emojis
π¨βπ©βπ§ πΌ // replace emojis
I'm looking for a simple solution, a regex maybe. Thanks
/^(?:alternative1|alternative2|alternative3)*$/.test(str)
β Leela