I am trying to write a regex for a string that will be a person's name. These are the following restrictions:
- Can contain at most 1 - symbol (can be none)
- Can contain at most 1 ' symbol (can be none)
- There cannot be two spaces next to each other
- A space must be proceeded and followed by a letter (a-z or A-Z)
- There is a max of 20 characters for the string
- The string must start with a letter (a-z or A-Z)
This is the expression I have so far:
^(?!.*[ ]{2})(?!(.*?-){2})(?!(.*?'){2})([a-zA-Z])([(?<=[a-zA-Z]) (?=[a-zA-Z])][a-zA-Z0-9\-']*){0,19}$
What I am missing is checking to make sure the space is followed and preceded by a letter. Any advice on how to incorporate that is very welcome. Thanks!