正则表达式re – Regular Expressions 寻找指定的词

版权声明:凡由本人原创,如有转载请注明出处https://me.csdn.net/qq_41424519,谢谢合作 https://blog.csdn.net/qq_41424519/article/details/81978031
import re

patterns = ['that', 'this' ]
text = 'Does this text match the pattern?'

for pattern in patterns:
    print('Looking for "%s" in "%s" ->' % (pattern, text),)

    if re.search(pattern,  text):
        print ('found a match!')
    else:
        print ('no match')

猜你喜欢

转载自blog.csdn.net/qq_41424519/article/details/81978031
今日推荐