Actually, there are a great many more characters you can use in a file name, even heinous things like backspaces and newline characters. In fact, you may find it depends on the underlying file system. I vaguely remember a rule somewhere that allowed everything except the actual path separator.
One thing I always consider when deciding if something is valid is to use it. For example, you can validate the format of an email address with a (complex) regex but the only way to be certain it's fully valid is to send a hyperlink mail to it to verify it's received.
In your particular case, if you want to create a file with that name, you can try to create a temporary file, in a directory you're actually allowed to create files in. If the file is created successfully, you can be pretty sure it's a valid name :-) Of course, if you're creating a file, you may just want to create the real file. If you're opening an existing file, forget the regex, just try to open the file - no amount of complication in your regex will tell you if the file exists or is readable by you.
To be frank, though, I'd consider placing your own limitations on the allowed characters - I have, in the past, cursed people who were silly enough to create file names with CTRL characters in them, or one called -rf
that the rm
command had troubles with (until you figure out how to get around that).