Guest User

Untitled

a guest
May 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. --- nawiasy klamrowe ---
  2.  
  3. import re
  4.  
  5. pattern = r"0{1,20}$"
  6.  
  7. if re.match(pattern, "000"):
  8. print("Rzad wielkosci x^3")
  9.  
  10. if re.match(pattern, "000000"):
  11. print("Rzad wielkosci x^6")
  12.  
  13. if re.match(pattern, "000000000"):
  14. print("Rzad wielkosci x^9")
  15.  
  16. if re.match(pattern, "000000000000"):
  17. print("Rzad wielkosci x^12")
  18.  
  19. if re.match(pattern, "000000000000000"):
  20. print("Rzad wielkosci x^15")
  21.  
  22. if re.match(pattern, "000000000000000000"):
  23. print("Rzad wielkosci x^18")
  24.  
  25. if re.match(pattern, "000000000000000000000"):
  26. print("Rzad wielkosci x^21")
  27.  
  28. --- wyrazenia regularne ---
  29.  
  30. import re
  31.  
  32. pattern = r"spam"
  33.  
  34. if re.search(pattern, "tutaj jest spam"):
  35. print(re.search(pattern, "tutaj jest spam").span().__getitem__(1))
  36. else:
  37. print("nie znaleziono spamu")
  38.  
  39. print("-----")
  40.  
  41. pattern = r"spam"
  42.  
  43. match = re.search(pattern, "tutaj jest spam")
  44. if match:
  45. print(match.group())
  46. print(match.start())
  47. print(match.end())
  48. print(match.span())
  49.  
  50. --- znajdz i zamien ---
  51.  
  52. import re
  53.  
  54. str = "Kolor tego przedmiotu to czarny"
  55. pattern = r"czarny"
  56. newstr = re.sub(pattern, "czerwony", str)
  57. print(newstr)
  58.  
  59. print("-----")
  60.  
  61. pattern = r"cz..ny"
  62.  
  63. if re.match(pattern, "czerwony"):
  64. print("Polaczenie 1")
  65.  
  66. if re.match(pattern, "czarny"):
  67. print("Polaczenie 2")
  68.  
  69. print("-----")
  70.  
  71. pattern = r"^cz..ny$"
  72.  
  73. if re.match(pattern, "czerwony"):
  74. print("Polaczenie 1")
  75.  
  76. if re.match(pattern, "czarny"):
  77. print("Polaczenie 2")
Add Comment
Please, Sign In to add comment