I have the following function that finds the normal, decimal, and fraction numbers (and it keeps the leading zeros, and detects the sign of the numbers as I want to):
def extract_numbers(text):
numbers = re.findall(r"[-+]?\d*\.\d+|[-+]?\d*/\d+|[-+]?\d+", text)
return numbers
The problem occurs when I test it with a fraction number that has decimals in the numerator or the denominator:
print(extract_numbers('this is difficult to get: -124.01/11.1'))
Output:
['-124.01', '/11', '.1']
When I need it to be like:
['-124.01/11.1']
So how to adjust the regex to extract the numbers with this prioritization: fraction numbers with decimals then fraction numbers then decimal numbers and finally normal numbers