fork download
  1. import re
  2.  
  3. listofdci = [' Acid. L(+)-lacticum D4']
  4. description = ' Acid. L(+)-lacticum D4 250 mg'
  5.  
  6. teste=[]
  7. for x in listofdci:
  8. test2 = [f"{x}{y}" for x,y in re.findall(rf"{re.escape(x)}(?:\s*\([^()]*\))?\s*(\d+(?:[.,]\d+)*)\s*(m?g\b|)", description)]
  9. if test2:
  10. teste.extend(test2)
  11.  
  12. print(teste)
Success #stdin #stdout 0.04s 9272KB
stdin
Standard input is empty
stdout
['250mg']