skip to Main Content

Why this SELECT "»" REGEXP "^[-а-я]*$" SQL statement returns 1 (true). Symbol "»" doesn’t match this regular expression.

In other case, it works correctly with symbol "«":
BINARY after REGEXP doesn’t resolve problem

2

Answers


  1. i cant say whats your Problem. On Version 8.0.33 it works perfect

    sample

    Database changed
    mysql> SELECT VERSION();
    +-------------------------+
    | VERSION()               |
    +-------------------------+
    | 8.0.33-0ubuntu0.20.04.2 |
    +-------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT "»" REGEXP "^[-а-я]*$";
    +---------------------------+
    | "»" REGEXP "^[-а-я]*$"    |
    +---------------------------+
    |                         0 |
    +---------------------------+
    1 row in set (0.00 sec)
    
    mysql> 
    
    Login or Signup to reply.
  2. Mostly a guess but character ranges can be problematic in combination with localization as described in https://developers.redhat.com/articles/2023/04/06/tips-handling-rational-ranges-in-regular-expressions

    According to the MySQL documentation it uses the ICU library to handle regular expressions. And this one happens to have an interesting example which might be working for you.

    ^[p{Letter}&&p{script=cyrillic}]$
    

    (I’m not sure if it includes upper case letters)

    Logical AND or intersection. Match the set of all Cyrillic letters.

    https://unicode-org.github.io/icu/userguide/strings/regexp.html

    Apart from that you can try to explicit list all characters explicit instead of using a range.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search