0
re.match(r"^[0-9]+minutes?$", "10 minute")
不匹配匹配正则表达式?
我也用过:
re.match(r"\d+minutes?$", "10 minute")
re.match(r"^[0-9]+minutes?$", "10 minute")
不匹配匹配正则表达式?
我也用过:
re.match(r"\d+minutes?$", "10 minute")
您忘记添加模式(\s
)以匹配在两者之间的空间。
>>> re.match(r"\d+\sminutes?$", "10 minute")
<_sre.SRE_Match object; span=(0, 9), match='10 minute'>
因为re.match
尝试匹配从一开始输入字符串,你不需要把开始锚^
。
你忘了'+'之间的空间'minutes' – fredtantini 2014-10-31 14:58:57
而且'minutes' VS'minute' – CoryKramer 2014-10-31 14:59:13
@Cyber他做的S可选的,所以没有问题。 – 2014-10-31 15:00:33