alist icon indicating copy to clipboard operation
alist copied to clipboard

隐藏功能的正则不支持断言

Open Sdator opened this issue 3 years ago • 3 comments

Please make sure of the following things

  • [X] I have read the documentation.
  • [X] I'm sure there are no duplicate issues or discussions.
  • [X] I'm sure it's due to alist and not something else(such as Dependencies or Operational).
  • [X] I'm sure I'm using the latest version

Alist Version / Alist 版本

v3.2.1

Driver used / 使用的存储驱动

All

Describe the bug / 问题描述

场景:只显示特定格式文件而隐藏其他文件或文件夹。

在元信息中的隐藏填入以下正则,以下正则在vscode、js中测试过可行如果写错了或你有更好的办法请告诉我

.*\.(?!mp4$).*

保存后,右上角提示红色错误信息

..(?!mp4$). is illegal: error parsing regexp: invalid or unsupported Perl syntax: (?!

测试过 (?!exp)(?<!exp) 两种断言都会报错,猜测是特殊字符触发了字符串的安全过滤?

建议

Alist目前的正则不太友好,很多对正则不熟悉的人无法通过它来实现一些比较复杂的过滤,希望能加入一些UI组件来帮助用户。

比如我们可以内置一些选项让用户去勾选或填写

文件过滤

  • 匹配的是文件还是文件夹还是所有

    • [ ] 文件
    • [ ] 文件夹
    • [ ] 所有
  • 匹配的前缀、匹配的后缀(应该是大多数人需要的),匹配的关键字

    • [用户编辑框]
  • 功能

    • [ ] 隐藏
    • [ ] 显示

这样当我想要只显示mp4和mp3文件时我可以这样做

第一条过滤:

  • [x] 所有
  • [x] 关键字
    • "*"
  • [x] 隐藏

第二条过滤:

  • [x] 文件
  • [x] 后缀
    • "mp4,mp3"
  • [x] 显示

通过以上两条规则我们就实现了只显示mp4和mp3类型的文件,规则优先级是从上到下,所以它会先隐藏掉所有文件然后只显示我们感兴趣的文件。当然这只是一个抛砖引玉的方法,可以实现的方式还有很多比如大家熟悉的 .gitignore

Reproduction / 复现链接

没有链接

Logs / 日志

.*\.(?!mp4$).* is illegal: error parsing regexp: invalid or unsupported Perl syntax: `(?!`

Sdator avatar Oct 19 '22 20:10 Sdator

Thanks for opening your first issue here! Be sure to follow the issue template!

welcome[bot] avatar Oct 19 '22 20:10 welcome[bot]

Negative lookahead isn't supported for technical reasons, specifically because it conflicts with the O(n)-time guarantees of the library. See the golang-nuts group discussion about this, as well as the Caveats section in Regular Expression Matching in the Wild.

https://stackoverflow.com/questions/26771592/negative-look-ahead-in-go-regular-expressions

xhofe avatar Oct 20 '22 01:10 xhofe

Hello, this issue has been inactive for more than 30 days and will be closed if inactive for another 30 days.

github-actions[bot] avatar Dec 01 '22 00:12 github-actions[bot]

Hello @, this issue was closed due to inactive more than 60 days. You can reopen or recreate it if you think it should continue.

github-actions[bot] avatar Jan 22 '23 00:01 github-actions[bot]