python 正则表达式 不知道是什么原因为什么匹配不出D?

#coding=utf-8
import re

title = "下列污染形式中不属于生态破坏的是(D)"

ret = re.match("[A-D]",title)
if ret:
print("匹配 %s 符合要求" % ret.group())
else:
print("无匹配")

中文和英文在一起需要重新编码么

你需要用search,match是全匹配

ret = re.search("[A-D]",title)

re.match 尝试从字符串的开始匹配一个模式

re.search函数会在字符串内查找模式匹配,只到找到第一个匹配然后返回,如果字符串没有匹配,则返回None。

你需要用search,match是全匹配
ret = re.search("[A-D]",title)