How to detect arabic or persian character in c # string?

I want to define an Arabic or Persian character in a string.

For example:

string search = "مشخصات، قیمت و خرید لپ تاپ 15 اینچی ایسر مدل Aspire ES1-533-C4UH"

and return true

and search in string = "Aspire ES1-533-C4UH"

and return false

string pattern = @"^[\p{IsArabic}\s\p{N}]+$";
string input = @"مشخصات، قیمت و خرید لپ تاپ 15 اینچی ایسر مدل Aspire ES1-533-C4UH";
RegexOptions options = RegexOptions.RightToLeft;"

foreach (Match m in Regex.Matches(input, pattern, options))
{
    if(m.Value !="")
    {
        bool x=true;
    }
    else
        x=false;
}

but it does not work.

+6
source share
1 answer

Try using this (I use it and it works).

This one Regexaccepts all Arabic letters over UTF ranges.

Regex regex = new Regex("[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
return regex.IsMatch(text);
+5
source

All Articles