Regex that matches Camel and Pascal Case

camelcasing, parsing, pascalcasing, regex

Solution

camelCase:

^[a-z]+(?:[A-Z][a-z]+)*$

PascalCase:

^[A-Z][a-z]+(?:[A-Z][a-z]+)*$

Problem

I'm about to write a parser for a language that's supposed to have strict syntactic rules about naming of types, variables and such. For example all classes must be PascalCase, and all variables/parameter names and other identifiers must be camelCase. For example `HTMLParser` is not allowed and must be named `HtmlParser`. Any ideas for a regexp that can match something that is PascalCase, but does not have two capital letters in it?

Original source