Python regex 要在线结束时匹配标点符号
如果优惠以大写字母和结束,我需要比较 [?.!] 在 Python.
编辑
他必须有 [?.!]
只要
在最后,
但要允许其他标点符号在提案中
在一些变化之后,它不起作用,我知道那部分
它是正确的,但结束时标点符号的对应不正确。
编辑
他必须有 [?.!]
只要
在最后,
但要允许其他标点符号在提案中
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]
它是正确的,但结束时标点符号的对应不正确。
没有找到相关结果
已邀请:
3 个回复
詹大官人
赞同来自:
解释:
在哪里
^[A-Z]
寻找首都的首都
'[^?!.]*'
means everything in between start and end is ok except things containing
or
or
[?.!]$
must end with
or
or
涵秋
赞同来自:
Regex 演示:
https://regex101.com/r/jpqTQ0/2
出口:
http://ideone.com/7DTs5q
涵秋
赞同来自:
[A-Z]
. 您必须更改:
修正案
您想要在线结束时的大写字母和标点符号之间进行比较。