为什么下面的string1
regexp不匹配?我已经用this对它进行了测试,似乎我的正则表达式fu是准确的,所以我想我在python实现中肯定遗漏了一些东西:
import re
pattern = r".*W([0-9]+(\.5)?)[^\.]?.*$"
string1 = '6013-SFR6W4.5'
string2 = '6013-SFR6W4.5L'
print(re.match(pattern, string1)) # the return value is None
print(re.match(pattern, string2)) # this returns a re.match object
Here是显示此问题的交互式会话的屏幕截图。你知道吗
编辑
你知道吗系统版本产出3.4.3
我尝试了完全相同的代码,两种情况下我都匹配:
Python3.4:
python 2.7版:
尝试使用
pattern = r"^.*W([0-9]+(\.5)?)[^\.]?.*$"
,在开头加上^
。你知道吗在您发布的代码中,您有:
但是在你截图上的代码里
(注意,第一个模式末尾附近的
?
被第二个模式中的+
替换)当我运行您提供的代码时,会得到以下两个方面的返回值:
相关问题 更多 >
编程相关推荐