import re def numTidy(number_str): # Remove all characters except digits, '-' and '.' cleaned_str = re.sub(r'[^\d.-]', '', number_str) # Ensure only one leading negative sign if cleaned_str.count('-') > 1: cleaned_str = '-' + cleaned_str.replace('-', '', 1) # Ensure only one decimal point if cleaned_str.count('.') > 1: parts = cleaned_str.split('.') cleaned_str = parts[0] + '.' + ''.join(parts[1:]) # Remove trailing non-numeric characters cleaned_str = re.sub(r'[^0-9]+\Z', '', cleaned_str) # Validate and format the number try: number = float(cleaned_str) return str(number) # Return the cleaned number as a string except ValueError: return "" # Return an empty string if the cleaned string is not a valid number # The following line would be used in IDEA to call this function: # @Python("numTidy", AMOUNT)