接受特定文件类型的正则表达式

Regex to accept specific file types

我正在使用 BlueImp jQuery File Upload,在其手册中,需要正则表达式代码来填写您要上传的可接受的文件类型。到目前为止我这里有正则表达式:

/^image\/(gif|jpe?g|png)$|^application\/(csv|pdf|msword)$|^text\/plain$/i;

但这不支持其他文件类型,例如 docx。我想要的是以下文件类型:

doc,docx,xls,xlsx,ppt,pptx,jpg,png,gif,pdf,txt,csv

现代的 MS Office mime 类型与旧式的不同。所以以前是application/msword,现在是application/vnd.openxmlformats-officedocument.wordprocessingml.document

现在有很多特定的 mime 类型,但它们都是以 vnd. 开头,然后是 ms-openxmlformats-

因此,添加捕捉所有可能的现代 Office 文件类型的 mime 类型将反映:

/^image\/(gif|jpe?g|png)$|^application\/(csv|pdf|msword|(vnd\.(ms-|openxmlformats-).*))$|^text\/plain$/i;
//-----------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

此处列出了其他 mime 类型。 https://technet.microsoft.com/en-us/library/ee309278%28v=office.12%29.aspx