在 mysql 查询中执行反向通配符的有效方法?
我正在编写一个 Drupal 模块,但这个问题不是 Drupal 特定的。
Drupal 有一个名为 menu_router
的表,它将人类友好的 URL 与可以提取内容的实际 URL 相关联。例如:
+--------------------------------------------------------+
| admin/config/media/image-styles/edit/%/add/% |
| admin/config/media/image-styles/edit/%/effects/% |
| admin/structure/types/manage/%/comment/fields/%/delete |
| admin/structure/types/manage/%/comment/fields/%/edit |
+--------------------------------------------------------+
我有一个任意 url,我想确保它实际上映射到网站上的有效 url。但是,我无法轻松执行通配符查询,因为正如您在上面所看到的,通配符字符串已经作为列值存在,并且我的搜索条件将是匹配的!
例如,根据 Drupal 处理 URL 的方式,'arbitary/url/string/'
将匹配 'arbitary/%/string'
。
我可以查询以查看任何给定字符串是否与任何通配符 Drupal 样式 url 匹配的有效方法是什么?
I'm writing a Drupal module, but this question is not Drupal-specific.
Drupal has a table called menu_router
, where it associates human-friendly URLs to the actual url that can pull up content. For example:
+--------------------------------------------------------+
| admin/config/media/image-styles/edit/%/add/% |
| admin/config/media/image-styles/edit/%/effects/% |
| admin/structure/types/manage/%/comment/fields/%/delete |
| admin/structure/types/manage/%/comment/fields/%/edit |
+--------------------------------------------------------+
I have a arbitrary url and I want to make sure that it actually maps to a valid url on the site. However I can't easily do a wildcard query, because as you can see above, the wildcarded string already exists as the column value, and my search criteria would be the match!
So for instance, 'arbitrary/url/string/'
would match 'arbitary/%/string'
, according to the way Drupal handles URLs.
What's an efficient way I can query to see if any given string matches any of the wildcarded Drupal-style urls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您可以从 menu_router 的行中创建一个大模式(即每行模式的或),然后查看您的目标是否匹配。只要您不需要知道它与 menu_router 中的哪一行匹配即可。
I suppose you could make one big pattern out of the lines of menu_router (i.e. an OR of the pattern for each line), and then see if your target gets matched. So long as you don't need to know which of the lines in menu_router it matches, that is.