How to find if a few words exist in a string with regular expression in Python

1 Answer

0 votes
import re     

RegEx = [         
        re.compile(x)         
        for x in ['Python', 'Java', "Programming"]     
        ]     
    
s = 'Python is a programming language that lets you work quickly'     
    
for rx in RegEx:         
    print('{} -'.format(rx.pattern), end=' ')         
    if rx.search(s):             
        print('match')         
    else:             
        print('no match')
        
# Programming != programming

'''
run:

Python - match
Java - no match
Programming - no match

'''

 



answered Apr 27, 2019 by avibootz
edited Apr 27, 2019 by avibootz
...