SQL Regex最后一个字符搜索不起作用 [英] SQL Regex last character search not working

查看:67
本文介绍了SQL Regex最后一个字符搜索不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用正则表达式来查找特定的搜索,但是最后一个分隔符被忽略.

I'm using regex to find specific search but the last separator getting ignore.

必须搜索| 49213 [A-Z] |但搜索| 49213 [A-Z]

Must search for |49213[A-Z]| but searches for |49213[A-Z]

SELECT * FROM table WHERE (data REGEXP '/\|49213[A-Z]+\|/')

推荐答案

啊哈.那是相当微妙的.

Aha. That is rather subtle.

  1. \转义某些具有特殊含义的字符.
  2. 但是对于|(或")或.(任何字节")等似乎没有这样做.
  3. 因此,\||相同.
  4. 但是regexp解析器不喜欢将或"的任何一侧都设为空. (我怀疑这是一个错误").因此出现错误消息.
  1. \ escapes certain characters that have special meaning.
  2. But it does not seem to do so for | ("or") or . ("any byte"), etc.
  3. So, \| is the same as |.
  4. But the regexp parser does not like having either side of "or" being empty. (I suspect this is a "bug"). Hence the error message.

https://dev.mysql.com/doc/refman/5.7/zh-CN/regexp.html

要在正则表达式中使用特殊字符的文字实例,请在其前面加上两个反斜杠()字符. MySQL解析器解释一个反斜杠,而正则表达式库解释另一个反斜杠.例如,要匹配包含特殊+字符的字符串1 + 2,只有以下正则表达式的最后一个才是正确的:

To use a literal instance of a special character in a regular expression, precede it by two backslash () characters. The MySQL parser interprets one of the backslashes, and the regular expression library interprets the other. For example, to match the string 1+2 that contains the special + character, only the last of the following regular expressions is the correct one:

当您想要竖线字符时,最好的解决方法似乎是[|]\\|而不是\|.

The best fix seems to be [|] or \\| instead of \| when you want the pipe character.

总有一天,MySQL中的REGEXP解析器将像MariaDB中一样升级到PCRE.然后会有更多功能出现,并且这个错误"可能消失了.

Someday, the REGEXP parser in MySQL will be upgraded to PCRE as in MariaDB. Then a lot more features will come, and this 'bug' may go away.

这篇关于SQL Regex最后一个字符搜索不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆