Last active
May 19, 2020 11:08
-
-
Save kurzweil777/c7ecea0c7a07cc2b6717047c93a6a7ee to your computer and use it in GitHub Desktop.
Regular Expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
numbersRegex = re.compile(r'''\d''') #Разделяем только по цифрам | |
numbersRegex2 = re.compile(r'''[a-zA-Z]''') #Разделяем по буквам | |
numbersRegex3 = re.compile(r'''([a-zA-Z0-9]+)''') #Разделяем на группы | |
result = numbersRegex.findall('q1/w2/e3/r4/t5/y6') | |
result2 = numbersRegex2.findall('q1/w2/e3/r4/t5/y6') | |
result3 = numbersRegex3.findall('q1/w2/e3/r4/t5/y6') | |
print(result) #['1', '2', '3', '4', '5', '6'] | |
print(result2) #['q', 'w', 'e', 'r', 't', 'y'] | |
print(result3) #['q1', 'w2', 'e3', 'r4', 't5', 'y6'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment