I'm trying to create a regex that will validate a string that only consists of Pascal case and is limited to 10 characters.
What I've got so far is based on Alix Axel's answer to the following question: Regex that matches Camel and Pascal Case
So the regex I'm using to validate for Pascal case is:
^[A-Z][a-z]+(?:[A-Z][a-z]+)*$
But, I'm unable to limit this string to a defined amount of characters, I've tried using a quantifier in several places, but I can't get it to work the way I expect it to.
For instance, I would expect the following regex to validate for Pascal case and limit the amount of characters in the string to 5 characters
^[A-Z][a-z]+(?:[A-Z][a-z]+){0,4}$
But it actually validates the casing of the string (upper-case character followed by lower-case characters) 5 times over and won't match the 6th occurrence. E.g. the above will match the RegexCanBeHardSometimes
string, but won't match the RegexCanBeHardSomeTimes
string