# -*- coding:utf-8 -*- # @Time: 2020-12-04 # @Author: JennyLuo # @Description: import re #TODO:正则表达式第一个词是 Alice、Bob 或Carol;第二个词是 eats、pets 或throws; # TODO:第三个词是 apples、cats 或baseballs module =['Alice eats apples.', 'Carol eats 7cats.', 'Bob pets cats.', 'Carol throws Apples.', 'Carol throws baseballs.', 'BOB EATS CATS.', 'RoboCop eats apples.', 'ALICE THROWS FOOTBALLS.'] moduleRegex =re.compile(r'^(Alice |Bob |Carol )(eats |pets |throws )(apples|cats|baseballs).$',re.I) for i in range(6): MO = moduleRegex.search(module[i]) if MO is not None: print(MO.group()) continue
2020-12-14
最新推荐文章于 2024-08-16 00:28:12 发布