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

1 Answer

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

 



answered Apr 28, 2019 by avibootz
...