gpt4 book ai didi

MySQL REGEXP 匹配/或字段结束

转载 作者:行者123 更新时间:2023-11-28 23:17:25 26 4
gpt4 key购买 nike

我在 MySQL 数据库 (5.7.17-0ubuntu0.16.04.2) 中有很多路径,用户选择了一系列路径,我想选择所有这些路径和下面的路径,但是我已经遇到问题。

假设用户想要“/root/K”我需要做一个选择:

a. /root/K%
b. /root/K

如何让 REGEXP 匹配字段或/的结尾?

我试过以下方法:

原始查询:

where path REGEXP ('/root/K/|/root/J/J/')  # this works but doesn't show the items in that path, only ones below

where path REGEXP '/root/K[/\z]' # does the same as above
where path REGEXP '/root/K(?=/|$)' # Get error 1139, repetition-operator invalid

我也试过:Regex to match _ or end of string但这会产生错误 1139

还有什么建议吗?

最佳答案

不支持环视,不支持 MySQL 正则表达式中的 \z anchor 。您可以使用普通的捕获组:

WHERE path REGEXP '/root/K(/|$)'

会匹配

  • /root/K - 文字字符序列
  • (/|$) - / 或条目结束。

关于MySQL REGEXP 匹配/或字段结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43255721/

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