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) )
aW1wb3J0IHJlCnBhdHRlcm4gPSByIlwqezJ9fFwqKFteKl0qKVwqIgp0ZXh0ID0gIkhlbGxvICp0aGVyZSogYXJlIHR3byBhc3RlcioqZXMgbmV4dCB0byBlYWNoIG90aGVyIgpwcmludCggcmUuc3ViKHBhdHRlcm4sIGxhbWJkYSB4OiBmJzxlbT57eC5ncm91cCgxKX08L2VtPicgaWYgeC5ncm91cCgxKSBlbHNlIHguZ3JvdXAoKSwgdGV4dCkgKQ==