I don't think you need to use regex for your use case you can just use the length of the emoji:
import emoji
NUM_COLUMNS = 4
TABLE_COLUMN_WIDTH = 18
def is_emoji(s):
return s in emoji.UNICODE_EMOJI
def is_default_emoji(s):
return len(s) == 1 and s in emoji.UNICODE_EMOJI
def get_default_emoji(s):
return s[0] if s in emoji.UNICODE_EMOJI else None
def pretty_print_line(line):
print(''.join(word.ljust(TABLE_COLUMN_WIDTH) for word in line.split()))
text = "poli kariku fans adi like ππ» ππΌ ππ½ ππΎ ππΏ π sub tharamo"
pretty_print_line("string is_emoji is_default_emoji get_default_emoji")
print("=" * NUM_COLUMNS * TABLE_COLUMN_WIDTH)
for s in text.split():
pretty_print_line(f'{s} {is_emoji(s)} {is_default_emoji(s)} {get_default_emoji(s)}')
Output:
string is_emoji is_default_emoji get_default_emoji
========================================================================
poli False False None
kariku False False None
fans False False None
adi False False None
like False False None
ππ» True False π
ππΌ True False π
ππ½ True False π
ππΎ True False π
ππΏ True False π
π True True π
sub False False None
tharamo False False None
You could use some logic similar to get_default_emoji
for your use case since it returns the same emoji regardless of the presence or lack of presence of a skin tone modifier.