How can I tell if a string starts with an emoji or not in Lua 5.2?

217 Views Asked by At

I know trying to deal with emojis in a string can get complicated in some cases, but in case I only wanted to know if a string starts with an emoji (any) or not, is there an easy way?

Sorry if it finally turned to be a very basic question, but the only thing that search reports to me for now is this C# one: How can i tell a string starts with an emoji and get the first emoji in the string, without using regex? that I don't even know how to take... Thank you.

1

There are 1 best solutions below

7
ESkri On

To simplify the solution, let's assume all emojies are belong to two Unicode ranges:
U+2600...U+27FF and U+01F000...U+01F6FF

-- returns true when UTF8-string starts with an emoji
function starts_with_emoji(s)
    if s:find"^\xF0\x9F[\x8C-\x9B]" or s:find"^\xE2[\x98-\x9F]" then
        return true
    end
end