java - 正则表达式可选,在 primefaces 中使用 allowTypes
问题描述
这是我的正则表达式,在本地 java 中,它可以工作,但是当我试图将它放在 p:fileUpload allowTypes 上时它不起作用。
我的目标是 1) "itrs" 或 "ITRS" 是必须的 2) "-draft" 或 "-DRAFT" 是可选的 3) ".csv" 或 ".CSV" 是必须的
我想尽可能过滤文件名和文件扩展名
这适用于我的本地:(itrs|ITRS)((-draft|-DRAFT)?)(\.|\/)(csv|CSV)$
解决方案
You may use either
allowTypes="/^(?:itrs|ITRS)(?:-draft|-DRAFT)?\.(?:csv|CSV)$/"
or, if dRaFt
and ItRS
are also accepted, you may shorten the pattern a bit using i
case insensitive modifier:
allowTypes="/^itrs(?:-draft)?\.csv$/i"
Note the use of /
regex delimiters here. Also, see an example in PrimeFaces "FileUpload - Single" docs illustrating the use of regex delimiters.
NOTE: If you really need to match .
or /
before csv
, replace \.
with [.\/]
.
推荐阅读
- python-pptx - Python PPTX 模块安装问题
- php - 即使使用脚本,我的弹出窗口也不会显示
- python - Python 嵌入到 C++ 中
- visual-studio-2019 - 无需运行应用即可预览剃须刀设计
- node.js - 节点模式中的 sokect 客户端数据处理
- algorithm - 将数组划分为具有最小和差的固定大小的子集
- python-3.x - 如何在没有库的情况下在 Python 中找到两个向量之间的 L1-Norm/Manhattan 距离
- solaris - solaris:在标准输入上设置的 O_NDELAY:当进程退出时,shell 退出
- python - 排除 rdd 映射中的特定列
- python - 如何在 tkinter 中将用户输入目录作为函数返回?