0

I want to use split function of LUA 5.1 to split string of emoji characters without spaces and add space between ones, but I can't do it rightly. So I do it by this way, but it's wrong:

#!/usr/bin/env lua

local text = "‍‍‍‍‍⌚↔"
for emoji in string.gmatch(text, "[%z\1-\127\194-\244][\128-\191]*") do
    io.write(emoji .. " ")          
end

See in browser Firefox 65!

MY WRONG RESULT: ⌚ ↔

WAITED RESULT: ‍‍‍ ‍‍ ⌚ ↔

Dzmitry
  • 87
  • 1
  • 1
  • 7

1 Answers1

1
local text = "‍‍‍‍‍⌚↔"
for emoji in text
   :gsub("(.)([\194-\244])", "%1\0%2")
   :gsub("%z(\240\159\143[\187-\191])", "%1")
   :gsub("%z(\239\184[\128-\143])", "%1")
   :gsub("%z(\226\128\141)%z", "%1")
   :gmatch"%Z+" 
do
   print(emoji)
end
Egor Skriptunoff
  • 906
  • 1
  • 8
  • 23