MySQL REGEXP query - accent insensitive search

前端 未结 7 1924
清歌不尽
清歌不尽 2020-12-19 00:46

I\'m looking to query a database of wine names, many of which contain accents (but not in a uniform way, and so similar wines may be entered with or without accents)

7条回答
  •  甜味超标
    2020-12-19 00:58

    I had the same problem trying to find every record matching one of the following patterns: 'copropriété', 'copropriete', 'COPROPRIÉTÉ', 'Copropri?t?'

    REGEXP 'copropri.{1,2}t.{1,2} worked for me. Basically, .{1,2} will should work in every case wether the character is 1 or 2 byte encoded.

    Explanation: https://dev.mysql.com/doc/refman/5.7/en/regexp.html

    Warning
    The REGEXP and RLIKE operators work in byte-wise fashion, so they are not multibyte safe and may produce unexpected results with multibyte character sets. In addition, these operators compare characters by their byte values and accented characters may not compare as equal even if a given collation treats them as equal.

提交回复
热议问题