【发布时间】:2017-09-30 21:41:11
【问题描述】:
如果一个句子在 Python 中以大写开头并以 [?.!] 结尾,我需要匹配。
EDIT它必须有 [?.!] only 在结尾但允许句子中的其他标点符号
import re
s = ['This sentence is correct.','This sentence is not correct', 'Something is !wrong! here.','"This is an example of *correct* sentence."']
# What I tried so for is:
for i in s:
print(re.match('^[A-Z][?.!]$', i) is not None)
它不起作用,经过一些更改我知道^[A-Z] 部分是正确的,但匹配末尾的标点符号不正确。
【问题讨论】:
标签: python regex python-3.x match