Look at right side on regex101 have explanation.
Think i have link to Regex101 a couple time before when you have about Regex
as eg search,findall,match can all be used to split and and solve this case.
re.spilt is more specialized and as name say more about splitting and it handle groups different.
Gribouillis regex pattern also work with re.spilt if add a group to it
Think i have link to Regex101 a couple time before when you have about Regex
Quote:on what basis should i make the choice between re.split() vs. re.search()?Many of regex method work in a similar way,but have specific use case they work better.
as eg search,findall,match can all be used to split and and solve this case.
re.spilt is more specialized and as name say more about splitting and it handle groups different.
Gribouillis regex pattern also work with re.spilt if add a group to it
()
import re def split_suffix(arg): return re.split(r"([+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)", arg)[1:] if __name__ == '__main__': lst = [ "144mHz", "1.296GHz", "100m/h", "1.25E-20watts", "1.23e+07GHz", "3.45e-4mHz", "12345abc", ] for n in lst: print(f'{n:<13} {split_suffix(n)}')
Output:144mHz ['144', 'mHz']
1.296GHz ['1.296', 'GHz']
100m/h ['100', 'm/h']
1.25E-20watts ['1.25E-20', 'watts']
1.23e+07GHz ['1.23e+07', 'GHz']
3.45e-4mHz ['3.45e-4', 'mHz']
12345abc ['12345', 'abc']