正则表达式字符串不匹配

F. *_*kes 3 python regex

我在使用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!"
Run Code Online (Sandbox Code Playgroud)

ale*_*xis 6

re.match“锚定”到字符串的开头。使用re.search


Exp*_*lls 6

阅读文档:http://docs.python.org/2/library/re.html#re.match

如果在零个或多个字符开头字符串

你想用re.search(或re.findall)