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!"
Read the documentation: http://docs.python.org/2/library/re.html#re.match
If zero or more characters at the beginning of string
You want to use re.search (or re.findall)
re.match is "anchored" to the beginning of the string. Use re.search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With