# PHP Regex expression to validate a name input

As part of my validation I have the following regex expression:

    ^
# Prevent 3+ consecutive letters: 'wheee'
(?!\w*([a-zA-Z])\g{-1}{2,})

[a-zA-Z](?:[a-zA-Z]|'(?!')){0,}

# Words or '&' are space or hyphen separated
(?:
[ -]

# Prevent 3+ consecutive letters: 'wheee' (for rest of words)
(?!\w*([a-zA-Z])\g{-1}{2,})
(?:[a-zA-Z]|'(?!')){1,}
|
[ -]
&
)*\$


I was wondering the effectiveness of the expression and/or possible pitfalls?

• I'm missing a short explanation why you need this expression and what you try to achieve? Oct 13, 2017 at 19:47

One possible pitfall is that several celebrities cannot pass your "validation" code. Do you really want Renée Zellweger and Goran Ivanišević being mad at you?

[a-zA-Z]


You use both lowercase and uppercase everywhere. This can possibly be symplified with (inline) modifiers:

(?i)[a-z]


Personally I use quantifiers as a "sugar" instead of explicit interval specifying:

{0,} ==> *
{1,} ==> +

• would there be any speed or other benefit to using quantifiers as a "sugar" instead of explicit interval specifying? Aug 14, 2017 at 15:10