it's a mouthful, but changing the ending regex from
fr'^[^\d]*{escape(amount)}[^\d]*$'
to
fr'^([^\d](?<!\$None)(?<!\$nan))*{escape(amount)}([^\d](?<!\$None)(?<!\$nan))*$'
catches the cases where extra numbers that don't look like numbers (i.e. $None and $nan) are printed
it's a mouthful, but changing the ending regex from
fr'^[^\d]*{escape(amount)}[^\d]*$'
tofr'^([^\d](?<!\$None)(?<!\$nan))*{escape(amount)}([^\d](?<!\$None)(?<!\$nan))*$'
catches the cases where extra numbers that don't look like numbers (i.e. $None and $nan) are printed