[Solved] Set a maximum length, requirement for space and minimum characters


You can do that using the following regex:

/^(?!.{36,})[a-z'-]{2,}\s[a-z'-]{2,}/gmi

See this in action at Regex101

Explanation

This matches strings that suit the following criteria:

  1. ^(?!.{36,}) It is not 36 characters or longer
  2. [a-z'-]{2,} Starts with a word containing only “a” – “z”, “‘” and “-“
  3. \s followed by a whitespace
  4. [a-z'-]{2,} followed by a word like decribed in 2.

you should however specify the following flags: gmi:

  1. g Get all matches, not just the first one
  2. m Treats lines seperately
  3. i Match without case-sensisitivity, since this was not a requirement and would have blown up the expression a bit 😉

5

solved Set a maximum length, requirement for space and minimum characters