fork download
  1. import re
  2.  
  3. def show():
  4. newresult = ['Naproxen 500 Active ingredient Ph Eur','Croscarmellose sodium 22.0 mg Disintegrant Ph Eur','Povidone K90 11.0 Binder 56 Ph Eur','Water, purifieda','Silica, colloidal anhydrous 2.62 Glidant Ph Eur','Water purified 49 Solvent Ph Eur','Magnesium stearate 1.38 Lubricant Ph Eur']
  5. all_extract = []
  6. for i in newresult:
  7. res = re.match(r'^(?:(?!.*\d\.\d)(.*?)\s*\b(\d+(?:\s*mg)?)\b\s*(.*)|((?:(?!\d+\.\d).)*?)\s*\b(\d+\.\d+(?:\s*mg)?)\b\s*(.*))$', i)
  8. if res:
  9. all_extract.append(list(filter(None, res.groups())))
  10. else:
  11. print("ONLY INTEGER")
  12. regex_integer_part = re.split(r'\s+(\d+(?:\.\d+)?)\s+', i, 1)
  13. all_extract.append(regex_integer_part)
  14. return all_extract
  15.  
  16. print(show())
Success #stdin #stdout 0.02s 9660KB
stdin
Standard input is empty
stdout
ONLY INTEGER
[['Naproxen', '500', 'Active ingredient  Ph Eur'], ['Croscarmellose sodium', '22.0 mg', 'Disintegrant  Ph Eur'], ['Povidone K90', '11.0', 'Binder 56 Ph Eur'], ['Water, purifieda'], ['Silica, colloidal anhydrous', '2.62', 'Glidant  Ph Eur'], ['Water purified', '49', 'Solvent  Ph Eur'], ['Magnesium stearate', '1.38', 'Lubricant  Ph Eur']]