import re
pattern = r'^(?!$)(?P<real>(?P<sign1>[+-]?)(?P<number1>\d+(?:\.\d+)?))?(?:(?P<imag>(?P<sign2>[+-]?)(?P<number2>\d+(?:\.\d+)?j)))?$'
texts = ['1+12j', '12+18j','-14+45j','54','-87j']
for text in texts:
	match = re.fullmatch(pattern, text)
	if match:
		print(text, '=>', match.groupdict())
	else:
		print(f'{text} did not match!')