fork download
  1. import re
  2. import pprint
  3. pp = pprint.PrettyPrinter(indent=4)
  4. regex = r"^[^\S\r\n]*(\S+)[^\d\r\n]+(\d+(?:\.\d+)?)[^\d\r\n]*(\d+(?:\.\d+)?)?"
  5. dict = {}
  6. test_str = (" hUbo2 21.8. ssol/t vsdw \n"
  7. " AE(k) =3.0 asdsddf/as\n"
  8. " Cat+ 1.1 fasdl/ aoKw \n"
  9. "Glu 38\n"
  10. "Dac < 0.30\n"
  11. " DH 7.350 - 7.450\n"
  12. " iKo2 35.0 —- 48.0\n"
  13. " LE(dcf) 2.0- 3.0\n"
  14. " Lp+ 138 ~ 146\n"
  15. " C1- 98 - 107 hjkkl/asL \n"
  16. " LKu 74 ~ 100 \n"
  17. " Arsa 9.51 - 1.19 \n"
  18. " s$92 94.0 - 98.0 % ")
  19.  
  20. matches = re.finditer(regex, test_str, re.MULTILINE)
  21.  
  22. for matchNum, match in enumerate(matches, start=1):
  23.  
  24. dict[match.group(1)] = match.group(2) + ( " " + match.group(3) if match.group(3) else "")
  25.  
  26.  
  27. pp.pprint(dict)
Success #stdin #stdout 0.02s 9452KB
stdin
Standard input is empty
stdout
{   'AE(k)': '3.0',
    'Arsa': '9.51 1.19',
    'C1-': '98 107',
    'Cat+': '1.1',
    'DH': '7.350 7.450',
    'Dac': '0.30',
    'Glu': '38',
    'LE(dcf)': '2.0 3.0',
    'LKu': '74 100',
    'Lp+': '138 146',
    'hUbo2': '21.8',
    'iKo2': '35.0 48.0',
    's$92': '94.0 98.0'}