How to match sequences of specific character followed by any one character form string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyx - aaXY.aaAyyy-aABCaxYxxyYaxaa.'    
pattern = 'x.'  # 'x' followed by any one character

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

Found: 'xy'
Found: 'x '
Found: 'xY'
Found: 'xx'
Found: 'xa'

'''

 



answered Apr 27, 2019 by avibootz
...