I'm developing a system that uses mysql REGEXP to find some rows.
In xampp localhost, that works good.
I have this query:
我正在开发一个使用mysql REGEXP来查找某些行的系统。在xampp localhost中,这很好用。我有这个问题:
SELECT COUNT(*) FROM users WHERE departments REGEXP '\\D(7|1|2|3|4|5|6)\\D' LIMIT 0, 25
And it returns some rows that match my REGEXP.
它返回一些与我的REGEXP匹配的行。
This is departments column
value of one of my users
table rows that must match REGEX: [1,3,4,6,7]
这是必须与REGEX匹配的我的一个用户表行的departments列值:[1,3,4,6,7]
With same database and same data in users
table, I uploaded my project files and database, But it doesn't return any values.
I used to test my query in Navicat Premium
directly, and again it was not returning any rows.
mysql version in my localhost is 4.6.5.2 and in my online version is 4.6.6.
Do you think I am forgetting something?
Any comments, offers, suggestions is appreciated.
使用相同的数据库和用户表中的相同数据,我上传了我的项目文件和数据库,但它没有返回任何值。我曾经直接在Navicat Premium中测试我的查询,并且它再次没有返回任何行。我的localhost中的mysql版本是4.6.5.2,我的在线版本是4.6.6。你觉得我忘了吗?任何评论,优惠和建议表示赞赏。
1 个解决方案
#1
2
Replace your pattern with
用。替换你的模式
REGEXP '[^0-9][1-7][^0-9]'
\D
is not supported and you can use a range in the bracket expression.
\ D不受支持,您可以在括号表达式中使用范围。
Pattern details
-
[^0-9]
- any char but digit -
[1-7]
- a digit from1
to7
-
[^0-9]
- any char but digit
[^ 0-9] - 任何字符但数字
[1-7] - 1到7之间的数字
[^ 0-9] - 任何字符但数字
If you need to also match at the start/end of string, use
如果您还需要在字符串的开头/结尾处匹配,请使用
REGEXP '(^|[^0-9])[1-7]($|[^0-9])'
The (^|[^0-9])
group matches either start of string (^
) or any char but a digit and ($|[^0-9])
matches any non-digit or the end of string ($
).
(^ | [^ 0-9])组匹配字符串的开头(^)或任何字符,但数字和($ | [^ 0-9])匹配任何非数字或字符串的结尾($) 。
#1
2
Replace your pattern with
用。替换你的模式
REGEXP '[^0-9][1-7][^0-9]'
\D
is not supported and you can use a range in the bracket expression.
\ D不受支持,您可以在括号表达式中使用范围。
Pattern details
-
[^0-9]
- any char but digit -
[1-7]
- a digit from1
to7
-
[^0-9]
- any char but digit
[^ 0-9] - 任何字符但数字
[1-7] - 1到7之间的数字
[^ 0-9] - 任何字符但数字
If you need to also match at the start/end of string, use
如果您还需要在字符串的开头/结尾处匹配,请使用
REGEXP '(^|[^0-9])[1-7]($|[^0-9])'
The (^|[^0-9])
group matches either start of string (^
) or any char but a digit and ($|[^0-9])
matches any non-digit or the end of string ($
).
(^ | [^ 0-9])组匹配字符串的开头(^)或任何字符,但数字和($ | [^ 0-9])匹配任何非数字或字符串的结尾($) 。