为什么这个正则表达式不起作用 ({m, n})? [英] Why is this regular expression not working ({m, n})?
本文介绍了为什么这个正则表达式不起作用 ({m, n})?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图理解正则表达式,我在重复部分:{m, n}
.
我有这个代码:
<预><代码>>>>p = re.compile('a{1}b{1, 3}')>>>p.match('ab')>>>p.match('abbb')如您所见,两个字符串都与模式不匹配.为什么会这样?
解决方案
逗号后不能加空格,{1}
是多余的.
Trying to understand regular expressions and I am on the repetitions part: {m, n}
.
I have this code:
>>> p = re.compile('a{1}b{1, 3}')
>>> p.match('ab')
>>> p.match('abbb')
As you can see both the strings are not matching the pattern. Why is this happening?
解决方案
You shouldn't put a space after the comma, and the {1}
is redundant.
这篇关于为什么这个正则表达式不起作用 ({m, n})?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文