mysql query with regex unicode

后端 未结 2 1372
面向向阳花
面向向阳花 2021-01-27 14:37

I would like to make a mysql query to catch : أرأء

this char أ may be typed like: ( أ or إ or ا or

2条回答
  •  滥情空心
    2021-01-27 15:08

    The utf8 for those 4 variants of Alef are D8A3 D8A5 D8A7 D8A2. So,

    WHERE HEX(title) REGEXP '^(..)*D8(A3|A5|A7|A2)'
    

    will check for the presence of any of them.

    The ^(..)* matches any number of pairs of characters (hex, in this case) at the beginning of title, then look for any of those 2-byte utf8 codes.

    This might be what you are striving for:

    $SQL=" select * from work
        where HEX(title)
            REGEX '^(..)*D8(A2|A3|A5|A7)D8B1D8(A2|A3|A5|A7)D8A1';
    

    ^(..)* is to skip over an even number of hex characters (to keep aligned).
    D8(A2|A3|A5|A7) is the utf8 encoding for the 4 Alefs.
    D8B1 is for Reh.

提交回复
热议问题