\P{M}\p{M}*)+ ^[-a-zA-Z\p{L}']" /> \P{M}\p{M}*)+ ^[-a-zA-Z\p{L}']" /> \P{M}\p{M}*)+ ^[-a-zA-Z\p{L}']"/>

match names with unicode chars

179 Views Asked by At

can somebody help me to match following type of strings "BEREŽALINS", "GŽIBOVSKIS" in C# and js , I've tried

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

, and so on ... but nothing works . Thanks

2

There are 2 best solutions below

0
Spikeh On

Just wrote a little console app to do it:

    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();
    }

Works with the two examples you gave me, but not sure about all scenarios :)

0
buckley On

Can you give an example of what is should not match?

Reading your question it's like you want to match just string (on seperates line maybe). If thats the case just use

^.*$

In C# this becomes

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

And in javascript this is

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