PHP-RegEx for german full name with umlauts and some internationalisation

php, preg-match, regex

Solution

So, if someone finds this thread and is looking for the best possible answer, here it is:

(Thanx to all on this thread for good help!)

With this regex pattern:

^([^\$%\^*£=~@\d]+){2,30} ([^\$%\^\.*£=~@\d]+){2,30}+$

my list from above (original question) looks like this:

Possible variation (status now)(expected):

- "Hans Spitzer" (match)(yes)

- "hans spitzer" (match)(yes)

- "Hans-peter Österreicher" (match)(yes)

- "Dr. Anna-Marie Pelzer-Hahnenkamp" (match)(yes)

- "Dipl-Ing. Gerhard Meyer" (match)(yes)

- "Lisa-Maria Brandner-Kapeller" (match)(yes)

- "John Mc'Connor" (match)(yes)

- "John" (no-match)(yes)

- "Johann " (no-match)(yes)

- "Osama Al Sawarri" (match)(yes)

- "Frank F." (no-match)(yes)

- "Johann F. Kerner" (match)(yes)

- "Johann F Kerner" (match)(no)

- "li xian" (match)(yes)

- "Li Xian" (match)(yes)

- "Li Fu" (match)(yes)

- "li fu" (match)(yes)

(Explaination: E.g. "li fu" (match)(yes) means, the name "li fu" matches and "yes" it is expected so)

Thanx again to all, this pattern is exactly what I was after.

Best regards,

"Ingmar Erdös" (match)(yes)

PS: This pattern works perfect in ecma (javascript) based regex operations but seams not to work in prce based operations like preg_match in PHP. Does anybody have an idea how to convert ecma to prce based patterns??? Have searched google up and down but no converter at all is online... Please give me some ideas, hints or a solution. Thnx. in advance.

Problem

Dear Stackoverflowianers, Dear RegEx-Gurus, I was searching the web for regex pattern that checks the plausibility of a full name in german language. I found many posts on patterns without german umlauts aso... From all this posts and my logical understanding I build this pattern together yet: ``` ^([A-ZÖÄÜ]{0,1})([-a-zäöüß\.']{2,30})( {1}|-{1})([A-ZÄÖÜ]{0,1})([a-zäöüß']{0,30})( {1}|-{1})?([A-ZÖÄÜ]{0,1})([a-zäöüß']{0,30})(( {0,1}|-{1})([A-ZÖÄÜ]{0,1})([a-zäöüß']{0,30}))+$ ``` It should match the following possible variations (status now)(expected): - "Hans Spitzer" (match)(yes) - "hans spitzer" (match)(yes) - "Hans-peter Österreicher" (match)(yes) - "Dr. Anna-Marie Pelzer-Hahnenkamp" (match)(yes) - "Dipl-Ing. Gerhard Meyer" (no-match)(no) - "Lisa-Maria Brandner-Kapeller" (match)(yes) - "John Mc'Connor" (match)(yes) - "John" (no-match)(yes) - "Johann " (match)(no) - "Osama Al Sawarri" (match)(yes) - "Frank F." (no-match)(yes) - "Johann F. Kerner" (no-match)(yes) - "Johann F Kerner" (match)(no) - "li xian" (match)(yes) - "Li Xian" (no-match)(no) - "Li Fu" (no-match)(no) - "li fu" (match)(yes) (where status now means if it matches now and expected means if it should or should not match) I need to use this pattern for preg_match in PHP. I'd be so thankfull if somebody could help me to refine this pattern. As soon it is - nearly - perfect I will add it to http://gskinner.com/RegExr/ for public use (they have 2 or 3 fullname checks but they're not working well or not at all). Thx. in advance for your help... Best regards, Ingmar

Original source