Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Last active May 19, 2020 11:08
Show Gist options
  • Save kurzweil777/c7ecea0c7a07cc2b6717047c93a6a7ee to your computer and use it in GitHub Desktop.
Save kurzweil777/c7ecea0c7a07cc2b6717047c93a6a7ee to your computer and use it in GitHub Desktop.
Regular Expressions
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