Bug #70413 \d is not working in REGEXP for a MySQL query
Submitted: 25 Sep 2013 7:07 Modified: 3 Oct 2013 13:29
Reporter: Konrád Lőrinczi Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.5.31, 5.5.34, 5.6.14 OS:Linux (Debian Wheezy v7.1)
Assigned to: CPU Architecture:Any
Tags: Debian, number match, REGEXP, Wheezy

[25 Sep 2013 7:07] Konrád Lőrinczi
Description:
The \d is not working in REGEXP for a MySQL query.

How to repeat:
Example:
SELECT * from mdl_course WHERE `shortname` REGEXP '\d\d';

Result:
No result displayed.

Suggested fix:
Following result should give results:
SELECT * from mdl_course WHERE `shortname` REGEXP '\d\d';
[25 Sep 2013 7:12] Konrád Lőrinczi
Added version info.
[25 Sep 2013 7:30] Konrád Lőrinczi
Updating example query.

This query has a valid regular expression, but still does not result anything:
SELECT '2013-2014-1' REGEXP '\d{4}-\d{4}-\d{1}';

The following query will work correctly:
SELECT '2013-2014-1' REGEXP '[0-9]{4}-[0-9]{4}-[0-9]{1}';
[3 Oct 2013 13:29] MySQL Verification Team
Hello Konrád,

Thank you for the report.
Verified as described.

MySQL support POSIX expression [[:digit:]].

mysql> SELECT '1234-1234-12' REGEXP '[[:digit:]]{4}\-[[:digit:]]{4}\-[[:digit:]]{2}';
+------------------------------------------------------------------------+
| '1234-1234-12' REGEXP '[[:digit:]]{4}\-[[:digit:]]{4}\-[[:digit:]]{2}' |
+------------------------------------------------------------------------+
|                                                                      1 |
+------------------------------------------------------------------------+

http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp

Thanks,
Umesh
[12 Mar 2020 6:27] Mark Winters
It's now 2020 with MySQL version 10.2, and this is STILL broken.  Outrageous!  So having to remap all use of \d to [0-9] is "non critical"?  Will it have the same performance?