gpt4 book ai didi

python - 我将如何设计一个数据库来包含一组可与传入网址匹配的网址正则表达式(python)

转载 作者:太空宇宙 更新时间:2023-11-03 19:39:33 25 4
gpt4 key购买 nike

假设我在数据库中有以下一组网址

url                     data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more

鉴于任何野外网址,我想检查一下查看该 url 是否属于现有的一组 url 并获取相应的数据字段。

我的问题是:

  1. 我将如何设计数据库来做到这一点
  2. django 通过循环每个正则表达式并检查匹配来进行 url解析鉴于可能有 1000 个网址,这是解决此问题的最佳方法吗?
  3. 有我可以查看的现有实现吗?

最佳答案

"2. django does urlresolution by looping through each regex and checking for a match given that there maybe 1000's of urls is this the best way to approach this?"

"3. Are there any existing implementations I can look at?"

如果运行大量正则表达式确实出现问题,您应该查看 esmre ,这是一个用于加速大型正则表达式集合的 Python 扩展模块。它的工作原理是提取每个正则表达式的固定字符串并将它们放入 Aho-Corasick 中。 - 受启发的模式匹配器可以快速消除几乎所有的工作。

关于python - 我将如何设计一个数据库来包含一组可与传入网址匹配的网址正则表达式(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1145955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com