早教吧 育儿知识 作业答案 考试题库 百科 知识分享

python正则表达式中怎么表示不含abcde的字符串?就是说我要用compile来写一个字符串不含abcde任意一个字母:是c=re.compile("^abcde")吗?还是其他种写法

题目详情
python正则表达式中怎么表示不含abcde的字符串?
就是说我要用compile来写一个字符串不含abcde任意一个字母:
是c=re.compile("^abcde")吗?还是其他种写法
▼优质解答
答案和解析
rex = r'[^abcde]*'
re.match(rex, 'this is a string')

返回值是None则不匹配,反之匹配

当然先compile一下也很好.