Since this post (regex-for-windows-file-name) is redirected to this question, I assume its Windows file names.
And based on the comment and @Leon's link to @AndrewD's answer, I made this regex and it works for me.
/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$|([<>:"\/\\|?*])|(\.|\s)$/ig
According to the naming conventions (see Link above), I agree that “com0” should be a valid file name, but it does not work if you try to name the file “com0” on windows, so I assume this is not in article
So this regex will be safer
/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$|([<>:"\/\\|?*])|(\.|\s)$/ig
lale liley
source share