比较两个 glob 表达式

发布于 2024-11-17 03:10:05 字数 378 浏览 3 评论 0原文

有谁知道一种算法来检查两个通配符表达式中哪一个比另一个更通用? 例如,我想

*/foo/foo.bar 

*.bar

“显然第一个表达式包含在第二个表达式中”进行比较。我知道这对于正则表达式来说是不可能的(至少如果你没有足够的时间的话,就不可能,据我记得这是在复杂性类非初级中),但是对于通配符表达式来说这是可能的,它要少得多富有表现力。我尝试编写一个简单的 python 算法,但在特殊情况下它会变得非常糟糕。 有人知道是否有解决该问题的算法吗?

更新:

我不想使用任何强力算法,因为由于性能原因这通常不起作用

问候,

Gerald

Does anyone know an algorithm to check which of two wild card expression is more general than the other?
For example I'd like to compare

*/foo/foo.bar 

with

*.bar

Clearly the first expression is contained in the second. I know that is not possible for regex (at least not if you don't have a looooot of time, as far as I remember this is in complexity class Non elementary), but it could be possible for wild card expression which are far less expressive. I tried to put together a simple python algorithm, but it get's very nasty when it comes to special cases.
Anybody has an idea if there is an algorithm for that problem?

UPDATE:

I do not want to use any brute force algorithm, since this won't work in general, because of performance reasons

Regards,

Gerald

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随梦而飞# 2024-11-24 03:10:05

您基本上需要以某种方式找到一个与更一般的全局匹配但不与更具体的全局匹配的字符串。很明显,船长...

可能是用 0 个或多个随机符号替换 * 字符。

You basically need to find a string somehow that matches the more general glob but not the more specific one. Just being captain obvious...

Probably by replacing * character with 0 or more random symbols.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文