How to match Unicode character using .net?

I want to match Unicode character using regular expression. I have found this is possible using Unicode Category or Block or more precisely using these Unicode Categories and Supported Named Blocks.

The issue is I am not able to make it work using LINQPAD 4 and Regex.IsMatch function. For example, trying to match a simple Latin character like this:

Console.WriteLine(Regex.IsMatch("d", @"[000-07F]+"));

raises the following error:

ArgumentException4 parsing “[000-07F]+” – [x-y] range in reverse
order.

and using this:

Console.WriteLine(Regex.IsMatch("d", @"L{IsBasicLatin}{1}"));

gives me:

parsing “L{IsBasicLatin}{1}” – Unrecognized escape sequence L.

In my real case I am going to replace IsLatin with IsCyrillic, but I need to make it work with the Latin to be sure it is OK.

Could anyone tell what I am doing wrong?


Source: regex

Leave a Reply