The following seems to work; I've tried to be exhaustive (but a simplier way should exist)
data = '144mhz' Number, Units = re.search(r"([+\-]?\d+\.\d+[eE]?[+\-]?[\d]?[\d]?|[+\-]?\d+[eE]?[+\-]?[\d]?[\d]?)[\s+]?([a-z]+)", data.lower()).groups()With :
- [+\-]? => if a sign is encountered (if comes from the "?")
- \d+\.\d+ => for floats (the "+" indicates one or more occurences)
- [eE]?[+\-]?[\d]?[\d]? => for scientific notation with or without the sign, and with 2 digits max here
- | => means "or"
- [+\-]?\d+[eE]?[+\-]?[\d]?[\d]?)[\s+]? => same thing for intergers (the dot followed by "\d+" have been removed from the previous sentence)
- [[\s+]?=> if there's any space
- [a-z]+ => to get strings
- remember that parentheses indicate what you want to recover