How to match sequences of uppercase or lowercase letters from string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyx - aaXY.aaAyyy-aABCaxYxxyYaaa.'    
pattern = '[a-zA-Z]+'  # sequences of lowercase or uppercase letters

for match in re.findall(pattern, s):         
    print('Found: {!r}'.format(match))
    
    
'''
run:

Found: 'xyx'
Found: 'aaXY'
Found: 'aaAyyy'
Found: 'aABCaxYxxyYaaa'

'''

 



answered Apr 27, 2019 by avibootz
...