Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只想上传扩展名为 .csv 和 .txt 的文件,并且不区分大小写。
例如 .csv、.CSV、.CSV、.txt、.tXt、.TxT ...
我目前正在使用这个
(?i)[.](csv|txt)
但是当扩展名区分大小写时,它不起作用。
此正则表达式将帮助您进行客户端和服务器端验证:
^.*\.([cC][sS][vV]|[tT][xX][tT]??)$
如果您想要至少一个字符作为名称(在 .txt 或 .csv 之前),那么以下内容将有所帮助:
^.+\.([cC][sS][vV]|[tT][xX][tT]??)$
您需要以 (?-i) 结束它,例如:
(?i)[.](csv|txt)(?-i)