正则表达式字符串不匹配 [英] Regex string doesn't match

查看:68
本文介绍了正则表达式字符串不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用 Python 匹配字符串中的数字时遇到问题.虽然它应该明确匹配,但它甚至不匹配 [0-9] [\d] 或仅 0 单独.我的疏忽在哪里?

I'm having trouble matching a digit in a string with Python. While it should be clearly matched, It doesn't even match [0-9] [\d] or just 0 alone. Where is my oversight?

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

如果在字符串

您想使用re.search(或re.findall)

这篇关于正则表达式字符串不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆