IT-Academy

Python Regex

Jan 28th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1.  
  2. import re
  3.  
  4. print(list('here are some words'))
  5.  
  6. # Konvertovanie String na list a odstranenie medzier
  7. # Patern: r'\s*'
  8. # \s: medzera
  9. # *: 0 alebo viac
  10. print(re.split(r'\s*', 'here are some words'))
  11.  
  12. # () - Skupinkovanie alebo zahrnutie
  13. print(re.split(r'(\s*)', 'here are some words'))
  14.  
  15. print(re.split(r'(s*)', 'here are some words'))
  16.  
  17. print(re.split(r'[a-f]',"findqwenlaskdjriewasd"))
  18.  
  19. # Priznaky
  20. # re.I = Ignorecase
  21. # re.M = Multiline
  22. print(re.split(r'[a-f]',"FIndqwEnlaskdjriewasd"), re.I)
  23.  
  24. print(re.split(r'[a-f][a-f]',"FIndqwEnlaskdjriewasd"), re.I)
  25.  
  26. # \d: digits
  27. # \D - non-digits
  28. # \S - non-Space
  29. print(re.findall(r'\d',"ocinwe324 main st.ads"))
  30.  
  31. print(re.findall(r'\d{1,5}',"ocinwe324 main st.ads"))
  32.  
  33. print(re.findall(r'\d{1,5}\s\w+',"ocinwe324 main st.ads"))
  34.  
  35. print(re.findall(r'\d{1,5}\s\w+\s\w+\.',"ocinwe324 main st.ads"))
  36.  
  37. if __name__ == "__main__":
  38.     pass
Advertisement
Add Comment
Please, Sign In to add comment