我正在 python 上做练习,但我的正则表达式是错误的我希望有人可以帮助我,练习是这样的:
填写代码以检查传递的文本是否看起来像标准句子,即它以大写字母开头,后跟至少一些小写字母或空格,并以句号、问号或感叹号结尾
import re
def check_sentence(text):
result = re.search(r"^[A-Z]+[a-z]+[\s]+[a-z]+[\.!\?]$", text)
return result != None
print(check_sentence("Is this is a sentence?")) # True
print(check_sentence("is this is a sentence?")) # False
print(check_sentence("Hello")) # False
print(check_sentence("1-2-3-GO!")) # False
print(check_sentence("A star is born.")) # True
慕村225694
翻过高山走不出你
潇湘沐
慕娘9325324
万千封印
相关分类