我在用 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!"
最佳答案
阅读文档:http://docs.python.org/2/library/re.html#re.match
If zero or more characters at the beginning of string
您想使用re.search
(或re.findall
)
关于python - 正则表达式字符串不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16569067/