匹配名称与unicode字符

时间:2012-03-23 13:14:57

标签: c# regex character-properties

有人可以帮我在C#和js中匹配以下类型的字符串“BEREŽALINS”,“GŽIBOVSKIS”,我试过了

 \A\w+\z         (?>\P{M}\p{M}*)+             ^[-a-zA-Z\p{L}']{2,50}$

等等......但没有任何作用。 感谢

2 个答案:

答案 0 :(得分:0)

刚刚写了一个小控制台应用程序来做到这一点:

    private static void Main(string[] args) {
        var list = new List<string> {
            "BEREŽALINS",
            "GŽIBOVSKIS",
            "TEST"
        };
        var pat = new Regex(@"[^\u0000-\u007F]");
        foreach (var name in list) {
            Console.WriteLine(string.Concat(name, " = ", pat.IsMatch(name) ? "Match" : "Not a Match"));
        }

        Console.ReadLine();
    }

使用您给我的两个示例,但不确定所有场景:)

答案 1 :(得分:0)

您能举例说明匹配的内容吗?

阅读你的问题,就像你想要匹配字符串一样(也许在单独的行上)。如果是这种情况只需使用

^.*$

在C#中,这变为

foundMatch = Regex.IsMatch(SubjectString, "^.*$", RegexOptions.Multiline);

在javascript中这是

if (/^.*$/m.test(subject)) {
    // Successful match
} else {
    // Match attempt failed
}