ojek
ojek

Reputation: 10078

Unicode regex does not work

I have this string: "asdf" And it is not recognized by this regex: ^[\p{L}]{3,32}$. As far as I know, the \p{L} should match any unicode letter. Why doesn't it? When i replace it with A-Za-z it works fine, but i need unicode characters. How can i fix this?

Upvotes: 0

Views: 502

Answers (1)

Parimal Raj
Parimal Raj

Reputation: 20585

// [\p{L}]{3,32}

// A character with the Unicode property “letter” (any kind of letter from any language) «[\p{L}]{3,32}» Between 3 and 32 times, as many times as possible, giving back as needed (greedy) «{3,32}»

By definition : " is not a letter in any of the language!

Try this Regex : ^"[\p{L}]{3,32}"$

using System;
using System.Text.RegularExpressions;

public class Test
{
    public static void Main()
    {
        Console.WriteLine(Regex.IsMatch("\"asdf\"", "^\"[\\p{L}]{3,32}\"$"));  //True
    }
}

Upvotes: 0

Related Questions