import re
rx = r"(?<!\d)(\d+)\*\1(?!\d)|(\([\d+-]+\))\*\2"
texts = ["5*5", "3.14*4", "(10-4)*(10-4)"]
for text in texts:
  print( [f'{x.group(1) or ""}{x.group(2) or ""}' for x in re.finditer(r'(?<!\d)(\d+)\*\1(?!\d)|(\([\d+-]+\))\*\2', text)] )