1

How can to use regex for all utf8 character? for example I want to check this format by regex:

[1][الهه اردونی]

I used \w for checking persian character but it dosent worked:

^(\[1\])(\[\w+\])$

I also used this:

^(\[1\])(\[\u0600-\u06FF\])$

so how can I do that? Thanks for any helping

Elahe
  • 1,379
  • 2
  • 18
  • 34

3 Answers3

3

You can use something like so:

^(\[1\])(\[[ا-ی\s]+\])$
Farahmand
  • 2,731
  • 1
  • 24
  • 27
2

How about the regex

^(\[1\])\[[\p{L}\s]+\]$

example : http://regex101.com/r/cU1nQ8/1

  • \p{L} matches any kind of letter from any language
nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
2

You're almost there. You just need to include the range \u0600-\u06FF, the pattern to match spaces \s inside a character class like below.

^(\[1\])(\[[\u0600-\u06FF\s]+\])$

DEMO

String input = @"[1][الهه اردونی]";
Regex rgx = new Regex(@"^(\[1\])(\[[\u0600-\u06FF\s]+\])$");
foreach (Match m in rgx.Matches(input))
{
Console.WriteLine(m.Groups[1].Value);
Console.WriteLine(m.Groups[2].Value);
}

Output:

[1]
[الهه اردونی]

IDEONE

[\u0600-\u06FF\s]+ match one or more characters from the given list. - acts like a range operator only inside the character class.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274