import re
pattern = r"\*{2}|\*([^*]*)\*"
text = "Hello *there* are two aster**es next to each other"
print( re.sub(pattern, lambda x: f'<em>{x.group(1)}</em>' if x.group(1) else x.group(), text) )