MySQL regexp for Latin and non Latin characters

User avatar
axew3
w3all User
w3all User
Posts: 2228
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

MySQL regexp for Latin and non Latin characters

Post by axew3 »

Code: Select all

SELECT username FROM users WHERE username REGEXP [^-0-9A-Za-z _.@]
will detect Денис И. as containing unwanted characters, even if it do not contain unwanted characters, based on above regexp,
Денис И. in non Cyrillic, but in Latin chars it is Denis I. and so should be accepted as valid.

To resolve this issue, i've find out into MySQL documentation a possible easy solution, because alnum (alphabetic/numbers in place of a-zA-Z0-9) do not take care of what kind of characters it found, and manage/return the correct result in this way:

Code: Select all

SELECT username FROM users WHERE username REGEXP [^-[:alnum:] _.@]
MySQL reference: https://dev.mysql.com/doc/refman/8.0/en/regexp.html

Any other i've try fail, but anybody that know how could be possible to achieve the same in different way let know