import res = "1kgbutter2kilochilli30gmssalt"print( re.sub(r'\d+(?:kg|kilo|gm)s?', r' \g<0> ', s).strip() )
Standard input is empty
1kg butter 2kilo chilli 30gms salt
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!