我正在寻找一种高效的算法,能够找到与特定字符串匹配的所有模式。模式集可能非常大(超过100,000个),并且可能是动态的(随时添加或删除的模式)。模式不一定是标准的regexp,它们可以是regexp的子集或类似于shell模式的东西(即:)file-*.txt。最好使用正则表达式子集的解决方案(如下所述)。
仅供参考:我对基于RegExp列表的蛮力方法不感兴趣。
通过简单的正则表达式,我的意思是一个正则表达式支持?,*,+,字符类[a-z]和可能的逻辑运算符|。
为了阐明我的需求:我希望找到所有与URL匹配的模式:
http://site1.com/12345/topic/news/index.html
Run Code Online (Sandbox Code Playgroud)
响应应该是基于以下模式设置的这些模式。
http://*.site1.com/*/topic/*
http://*.site1.com/*
http://*
Run Code Online (Sandbox Code Playgroud)
模式集:
http://*.site1.com/*/topic/*
http://*.site1.com/*/article/*
http://*.site1.com/*
http://*.site2.com/topic/*
http://*.site2.com/article/*
http://*.site2.com/*
http://*
Run Code Online (Sandbox Code Playgroud)