Unicode正则表达式不起作用

时间:2013-02-07 21:18:22

标签: c# regex

我有这个字符串:"asdf" 这个正则表达式无法识别它:^[\p{L}]{3,32}$。据我所知,\p{L}应匹配任何unicode字母。为什么不呢?当我用A-Za-z替换它时工作正常,但我需要unicode字符。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

// [\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}»

根据定义:"不是任何一种语言的字母!

试试这个正则表达式:^"[\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
    }
}