How to find pattern matches with {number} in a string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyxxxyyyxyxxyy'    
pattern = 'xy{2}'  # 'x' followed by two 'y' 

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

Found: 'xyy'
Found: 'xyy'

'''

 



answered Apr 27, 2019 by avibootz
...