比较两个 glob 表达式
有谁知道一种算法来检查两个通配符表达式中哪一个比另一个更通用? 例如,我想
*/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上需要以某种方式找到一个与更一般的全局匹配但不与更具体的全局匹配的字符串。很明显,船长...
可能是用 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.