I want to detect Arabic or Persian character in a string.
For example:
search in string = "مشخصات، قیمت و خرید لپ تاپ 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 this doesn not work.
Try using this (I'm using it and it works).
This Regex
accepts all arabic letters by UTF ranges.
Regex regex = new Regex("[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
return regex.IsMatch(text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With