How to to get words ends with specific character from a string with regular expression in Python

1 Answer

0 votes
import re     
 
s = 'python xyx 234 aa4!@!4XY. paaAyyy984a ABCa-xYxx3yYa java aa.'   
pattern = r'\w+a\b'  # words ends with 'a'
 
for match in re.findall(pattern, s):         
    print('Found: {!r}'.format(match))
     
     
'''
run:
 
Found: 'paaAyyy984a'
Found: 'ABCa'
Found: 'xYxx3yYa'
Found: 'java'
Found: 'aa'
 
'''

 



answered Apr 28, 2019 by avibootz
...