You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写正则表达式匹配SUNSOLAR_Demo_0下sale_docs目录内容并排除其余路径

原正则问题原因

你写的^SUNSOLAR_Demo_0/My Documents/(?!CUSTOMER/sale_docs).*$逻辑完全相反,负向断言(?!CUSTOMER/sale_docs)的作用是匹配SUNSOLAR_Demo_0/My Documents/后没有跟着目标后缀的路径,刚好命中你要排除的内容,自然达不到效果。


可用正则方案

根据你的过滤逻辑选择对应正则即可:

方案1:直接匹配需保留的路径(命中即保留)

正则:

^SUNSOLAR_Demo_0/My Documents/CUSTOMER/sale_docs(/.*)?$

效果验证:

  • 匹配通过(保留):SUNSOLAR_Demo_0/My Documents/CUSTOMER/sale_docs/invoices/emails/sample.pdf
  • 匹配通过(保留):SUNSOLAR_Demo_0/My Documents/CUSTOMER/sale_docs(目录本身)
  • 匹配不通过(排除):SUNSOLAR_Demo_0/My Documents/CUSTOMER/unseal/mytest.doc
  • 匹配不通过(排除):SUNSOLAR_Demo_0/My Documents/PROVIDERS/orders/invoices.xls

方案2:匹配需排除的路径(命中即丢弃)

如果你的过滤规则是排除命中正则的内容,剩下的自动保留,用以下正则:

^(?!SUNSOLAR_Demo_0/My Documents/CUSTOMER/sale_docs(/.*)?$).*

内容的提问来源于stack exchange,提问作者101000101

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 08:45:04