How to Check If a SQL String Column Has Arabic Characters in MSSQL

There are multiple ways to find Arabic characters in Microsoft SQL Server, below are some examples:

If You Want to Select Only Arabic Characters in MSSQL Column

For example, if you want to filter ‘تجربة’, you can filter the column using a regular expression like so:

SELECT * FROM <MyTable> Where <MyArabicColumn> like N'%[أ-ي]%'

This will filter the column for any character that is included in the group ‘%[أ-ي]%’ which covers all Arabic characters. This is similar to [a-zA-Z] in the English alphabet.

If You Want to Select Arabic and Special Characters in MSSQL Column

In case you want to search for values like ‘تجربة/.\;}][‘ which contains Arabic characters or any special characters, you can use the below query:

SELECT * FROM <MyTable> Where <MyArabicColumn> like N'%[أ-ي]%' and <MyArabicColumn> like '%[ @\.\-]%' and <MyArabicColumn> not like '%[0-9]%' and <MyArabicColumn> not like '%[a-zA-Z]%'

This will match the string that contains Arabic letters matching the group ‘%[أ-ي]%’, and then match any special character using the group ‘%[ @.-]%’ and finally exclude any numbers and English letters using the two groups ‘%[0-9]%’ and ‘%[a-zA-Z]%’.

If You Want to Select Arabic Letters and Numbers in MSSQL Column

If you want to select any string containing numbers, special characters and Arabic letters like ‘11234تجربة’, you can use the below query:

SELECT * FROM <MyTable> Where <MyArabicColumn> like N'%[أ-ي]%' and <MyArabicColumn> like '%[0-9]%' and <MyArabicColumn> not like '%[ @\.\-]%'and <MyArabicColumn> not like '%[a-zA-Z]%'

This will match the string that contains Arabic letters matching the group ‘%[أ-ي]%’, and then match any numbers using the group ‘%[0-9]%’ and finally exclude any special characters and English letters using the two groups ‘%[ @.-]%’ and ‘%[a-zA-Z]%’.

If You Want to Select Arabic, Special Characters, and Numbers in MSSQL Column

Finally, if you want to select Arabic letters as well as special characters and numbers like for example ‘11234تجربة/.\;}][‘, you can use the below query:

SELECT * FROM <MyTable> Where <MyArabicColumn> like N'%[أ-ي]%' and <MyArabicColumn> like '%[0-9]%' and <MyArabicColumn> like '%[ @\.\-]%'and <MyArabicColumn> not like '%[a-zA-Z]%'

In this case, you can capture all the groups such as Arabic characters, numbers and special characters but exclude English letters.

And this was a brief code bit of regex filtering using SQL in Microsoft SQL server, hope this helps!


Hilal Hakla
Hilal Hakla

I’m a tech geek and a software engineer from Lebanon. I write and teach about software development using .Net, Azure and Sharepoint.

Leave a Reply