Regular Expressions 101

Regex of name or a firstname

Open Workspace
  • PCRE2 (PHP)
  • Match
1

Regular Expression

/
^((?:(?:[a-zA-Z]+)(?:-(?:[a-zA-Z]+))+)|(?:[a-zA-Z]+))$
/
gm

Description

Format detected:

"Jean" OR "Jean-Pierre" OR "Jean-Marie-Pierre"

Details :

Name[...-Name]

[...-Name] is optional, "Name" can be : a-z or A-Z no accent supported

Submitted by Massinissa CHAOUCHI