Mysql正则表达式错误#1139使用文字 - [英] Mysql regex error #1139 using literal -

查看:598
本文介绍了Mysql正则表达式错误#1139使用文字 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行此查询:

  SELECT列FROM表WHERE列REGEXP'[^ A-Za-z\ -$ \\ b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b 


#1139 - 从regexp中获得错误'无效字符范围'


字符类中的 - 未被转义,而是读取为无效范围。还有其他一些方法,假设要将mysql转义为字面值 -



这个正则表达式工程如预期在mysql之外, https://regex101.com/r/wE8vY5/1



我想出了另一种正则表达式,它是

  SELECT列FROM表WHERE列NOT REGEXP'([:alpha:] |  -  | \')'





这是一个SQL小提琴的问题, http://sqlfiddle.com/#!9/f8a006/1



另外,那里这里没有使用任何语言,查询正在DB级别运行。



PHP中的正则表达式: http://sandbox.onlinephpfunctions.com/code/10f5fe2939bdbbbebcc986c171a97c0d63d06e55



JS中的正则表达式: https://jsfiddle.net/6ay4zmrb/

解决方案

只需更改顺序。

  SELECT列FROM表WHERE列REGEXP'[^ -A-Za- z \'''


I tried running this query:

SELECT column FROM table WHERE column REGEXP '[^A-Za-z\-\']'

but this returns

#1139 - Got error 'invalid character range' from regexp

which seems to me like the - in the character class is not being escaped, and instead read as an invalid range. Is there some other way that it's suppose to be escaped for mysql to be the literal -?

This regex works as expected outside of mysql, https://regex101.com/r/wE8vY5/1.

I came up with an alternative to that regex which is

SELECT column FROM table WHERE column NOT REGEXP '([:alpha:]|-|\')'

so the question isn't how do I get this to work. The question is why doesn't the first regex work?

Here's a SQL fiddle of the issue, http://sqlfiddle.com/#!9/f8a006/1.

Also, there is no language being used here, query is being run at DB level.

Regex in PHP: http://sandbox.onlinephpfunctions.com/code/10f5fe2939bdbbbebcc986c171a97c0d63d06e55

Regex in JS: https://jsfiddle.net/6ay4zmrb/

解决方案

Just change the order.

SELECT column FROM table WHERE column REGEXP '[^-A-Za-z\']'

这篇关于Mysql正则表达式错误#1139使用文字 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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