I have a file named
Document.pdf and sometimes it is called
-12345678 is a random number.
I want to check a file is downloaded in folder. When the file is not finished it display
.fkasfmq is a random hash from the downloader and I don’t want it to match.
I try make a regex like
r'Document(?:[-0-9]+).pdf' and test it with either
Document-12345678.pdf it will always return false.
From my understanding
(?:[-0-9]+) means it can be or not in the set that matches any hyphen and any numbers before
You should mark it as optional with the
"?" symbol. Otherwise, you are requiring that the name should have the numbers and/or digits part.
Or as @anubhava pointed out in the comments, it can be simplified to:
- This way, it will also match e.g.
Also, you should consider putting the mark
"$" to signify end of string so that it doesn’t match e.g.