def test_B(): # ! /usr/bin/evn python # -*- coding:utf-8 -*- import re line = 'Cats are smarter than dogs dogs' matchObj = re.match(r'dogs', line) if matchObj: print('use match,the match string is:', matchObj.group()) else: print('No match string!!') matchObj = re.search(r'dogs', line) if matchObj: print('use search,the match string is:', matchObj.group()) else: print('No search match string!!')
执行结果如下:
No match string!! use search,the match string is: dogs