regex_clean_new.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # coding=utf8
  2. import re
  3. def print_clean(dims): ##alles raus was nicht relevant ist! und zeichen ersetzen!
  4. dims_new = {}
  5. reg_clean = r"ISO|[a-zA-Z]{4,}|^\d\s\d$|^[a-zA-Z]{2,}\d.*$|^[A-Z]{1}$|^mm$|^\d{2}\.\d{2}\.\d{4}|^-$|A\d|^\d{1}$|^[A-Za-z]{3,}\.?$|^\d{5}|^\d{1}\s\W\s\d"
  6. for dim in dims:
  7. if re.search(reg_clean, dim):
  8. continue
  9. else:
  10. coords = dims[dim]
  11. if re.search(r"b\s\d*\W?\d*\s.",dim):
  12. dim = dim.replace('b', u"\u27C2")
  13. if re.search(r"g\s\d*\W?\d*", dim):
  14. dim = dim.replace('g', u"\u232D")
  15. if re.search(r"f\s\d*\W?\d*", dim):
  16. dim = dim.replace('f', u"\u2225")
  17. if re.search(r"r\s\d*\W?\d*", dim):
  18. dim = dim.replace('r', u"\u25CE")
  19. if re.search(r"i\s\d*\W?\d*", dim):
  20. dim = dim.replace('i', u"\u232F")
  21. if re.search(r"j\s\d*\W?\d*", dim):
  22. dim = dim.replace('j', u"\u2316")
  23. if re.search(r"d\s\d*\W?\d*", dim):
  24. dim = dim.replace('d', u"\u2313")
  25. if re.search(r"c\s+\d*", dim):
  26. dim = dim.replace('c', u"\u23E5")
  27. if re.search(r"n\s+\d*", dim):
  28. dim = dim.replace('n', u"\u2300")
  29. if "È" in dim:
  30. dim = dim.replace('È', 'GG')
  31. if "`" in dim:
  32. dim = dim.replace('`', u"\u00B1")
  33. if "#" in dim:
  34. dim = dim.replace('#', "↔")
  35. if "⌀" in dim:
  36. dim = dim.replace('⌀', "Ø")
  37. reg12 = re.compile(r"(.*\d{1,4}\W?\d{0,4})\s?\+\s-\s?(\d{1,4}\W?\d{0,4})\s?(\d{1,4}\W?\d{0,3})") ##???? was machst du?? nach toleranzen suchen, mit +/- blabla
  38. reg13 = re.compile(r"(.*)\+\s\+\s(\d*\W\d*)\s(\d*\W\d*)(.*)")
  39. reg14 = re.compile(r"(\+\s?\d*,?.?\d*)\s*(\d*,?.?\d*)\s*(\+?\s?\-?\s?\d*,?.?\d*)")
  40. g = re.search(reg12, dim)
  41. f = re.search(reg13, dim)
  42. e = re.search(reg14, dim)
  43. if g:
  44. dim = re.sub(reg12, g.group(1) + " +" + g.group(2) + " -" + g.group(3), dim) # +/- toleranzen schön darstellen
  45. #print(dim)
  46. elif f:
  47. dim = f.group(1) + "+" + f.group(2) + " +" + f.group(3) + f.group(4)
  48. elif e:
  49. dim = e.group(2) + " " + e.group(1) + " " + e.group(3)
  50. dim = dim.replace(" ,",".").replace(", ",".").replace(",",".")
  51. dims_new[dim] = coords
  52. #for dim in dims_new:
  53. # print(dim)
  54. #print(dims_new)
  55. return dims_new