正则表达式字符串不匹配
发布于 2021-01-29 15:05:54
我在用Python将字符串中的数字匹配时遇到麻烦。尽管应该明确匹配,但甚至不匹配[0-9]
[\d]
或仅匹配0
。我的监督在哪里?
import re
file_without_extension = "/test/folder/something/file_0"
if re.match("[\d]+$", file_without_extension):
print "file matched!"
关注者
0
被浏览
99
1 个回答
-
阅读文档:http :
//docs.python.org/2/library/re.html#re.match如果在零个或多个字符 开头 的 字符串
您要使用
re.search
(或re.findall
)