| Bug #111785 | REGEXP needs double slash to escape dot for no reason, not documented | ||
|---|---|---|---|
| Submitted: | 17 Jul 2023 21:16 | Modified: | 18 Jul 2023 14:07 |
| Reporter: | teo teo | Email Updates: | |
| Status: | Not a Bug | Impact on me: | |
| Category: | MySQL Server | Severity: | S3 (Non-critical) |
| Version: | 8.0.18 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[17 Jul 2023 21:32]
teo teo
Apparently I cannot edit my own report, which is incredibly stupid.
Where I wrote:
```
How to repeat:
SELECT '_.' REGEXP '^(\.){2,2}$'
shoud return 1, returns 0 instead.
```
it should be the other way around:
```
How to repeat:
SELECT '_.' REGEXP '^(\.){2,2}$'
shoud return 0, returns 1 instead.
```
[18 Jul 2023 13:09]
MySQL Verification Team
Hi Mr. teo,
Please, always try to use our latest release.
With 8.0.33, we get :
+---------------------------+
| '_.' REGEXP '^(\.){2,2}$' |
+---------------------------+
| 1 |
+---------------------------+
Not a bug.
[18 Jul 2023 14:07]
teo teo
Please, always try to use our latest release.
> With 8.0.33, we get :
> +---------------------------+
> | '_.' REGEXP '^(\.){2,2}$' |
> +---------------------------+
> | 1 |
> +---------------------------+
Exactly, same as I do. I expected 0.
> Not a bug.
Care to elaborate?
[18 Jul 2023 14:17]
MySQL Verification Team
Hi, C escape sequences can be found in any C textbook. That means that '\' has to be written as '\\' for regular expressions and many other textual functions.

Description: The following: SELECT '_.' REGEXP '^(\.){2,2}$' should return false. In the regular expression, "\." is supposed to mean a literal dot. Instead, apparently MySQL treats the "\." as an unescaped ".", which matches any character, and therefore the query above returns true, i.e. 1. If I add an extra slash for no reason: SELECT '_.' REGEXP '^(\\.){2,2}$' then I get the result I initially expected. There's nothing in the docs that explains why the extra slash should be required. This sentence: ``` Note MySQL uses C escape syntax in strings (for example, \n to represent the newline character). If you want your expr or pat argument to contain a literal \, you must double it. (Unless the NO_BACKSLASH_ESCAPES SQL mode is enabled, in which case no escape character is used.) ``` besides being ridiculously vague (I shouldn't be expected to know how "C escape syntax in strings" works and I certainly can't know how "MySQL uses" it), it definitely does not explain the behavior in this case. How to repeat: SELECT '_.' REGEXP '^(\.){2,2}$' shoud return 1, returns 0 instead.