On a POSIX filesystem (MacOS, Linux, BSD, etc.), any character except ‘/’ can be part of a filename. So why are you limiting yourself to a couple of punctuation characters? The best regex to match filenames is: “[^/]+”
If you’re using Windows, it gets a bit trickier, but for reading the filesystem, “[^/\\\\]+” seems like it should be adequate. If you want to make sure you can create a filename on Windows, you’d have to exclude a few more characters. Nevertheless, excluding invalid characters still seems like a better approach than trying to include all the valid ones.
On a POSIX filesystem (MacOS, Linux, BSD, etc.), any character except ‘/’ can be part of a filename. So why are you limiting yourself to a couple of punctuation characters? The best regex to match filenames is: “[^/]+”
If you’re using Windows, it gets a bit trickier, but for reading the filesystem, “[^/\\\\]+” seems like it should be adequate. If you want to make sure you can create a filename on Windows, you’d have to exclude a few more characters. Nevertheless, excluding invalid characters still seems like a better approach than trying to include all the valid ones.