Bug #73277 REGEXP escape of - not escaped properly in character group

Submitted: 11 Jul 2014 13:23 Modified: 15 Jul 2014 13:55
Reporter: Robert Pazurek Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.537-35.1-log, 5.0.97, 5.1.74, 5.5.39, 5.6.21, 5.7.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: REGEXP

[11 Jul 2014 13:23] Robert Pazurek
Description:
In some cases the - character can not be escaped when in character group, depending on it's position.

How to repeat:
SELECT 'bla-blubb' REGEXP 'bla[2\-1]blubb'
throws: invalid character range (1139)

SELECT 'bla-blubb' REGEXP 'bla[1\-2]blubb'
returns: 0
should return: 1

SELECT 'bla2blubb' REGEXP 'bla[1\-3]blubb'
returns: 1
should return: 0

=> the last two are worse, since they silently behave unexpected!

Workaround: if \- is put to the end of the character group, it is escaped properly:

SELECT 'bla2blubb' REGEXP 'bla[13\-]blubb'
returns: 0 (correct)

SELECT 'bla-blubb' REGEXP 'bla[13\-]blubb'
returns: 1 (correct)

Suggested fix:
Escaping the - with a \ should work anywhere, no matter of the position in a character group.
[15 Jul 2014 13:55] Sveta Smirnova
Thank you for the report.

First of all escape character in regular expression is '\\', not single '\' (http://dev.mysql.com/doc/refman/5.6/en/regexp.html#operator_regexp), but in any case your complain regarding to SELECT 'bla-blubb' REGEXP 'bla[2\\-1]blubb'; is correct and repeatable even if I use '\\'. Bug is verified.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.043 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.