How to find Cyrillic font (russian characters)?

2019-09-07 06:08发布

问题:

Idea is to find all values that contains Cyrillic font (russian characters).

Something like:

SELECT CASE 
         WHEN Name LIKE /* Cyrillic font / russian characters */ THEN '1' 
         ELSE Name 
       END AS Filter

I can't find any info about It, so I can't provide what I've tried.

For example:

  Name
Александр -- This is Cyrillic (have russian characters, should return 1)
John      -- This should be returned as normal Name

Have you any ideas?

回答1:

As per comment:

This Q&A gives a good way of doing this in SQL-Server (Can't mark as duplicate, since it is a different kind of question):

Solution:

select *,                               --  ▼ space added here
       case when TheName like '%[^-A-Za-z0-9 /.+$]%'
         then '1'
         else TheName
      end as 'Filter'
  from CyrillicTest

You can either adjust the RegEx string to match all the Cyrillic characters or adjust it to cater for hyphenated ASCII names (and all other weird things parents put into their kids names). I am not sure about the speed of this against a big table, so please test it.

Testbed:

create table CyrillicTest
     ( TheID   int identity(1,1) not null,
       TheName nvarchar(50)      not null )

insert CyrillicTest
     ( TheName )
values
     ( 'AName' ),
     ( 'Александр' ),
     ( 'CName' )

Output:

TheID       TheName       Filter
----------- ------------- -------------
1           AName         AName
2           Александр     1
3           Thirdname     Thirdname