Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex that matches Camel and Pascal Case

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?

like image 289
Marcin Avatar asked Jan 20 '10 17:01

Marcin


People also ask

Is camelCase the same as PascalCase?

Camel case and Pascal case are similar. Both demand variables made from compound words and have the first letter of each appended word written with an uppercase letter. The difference is that Pascal case requires the first letter to be uppercase as well, while camel case does not.

What is camelCase and PascalCase in C#?

Camel Case (camelCase): In this standard, the first letter of the word always in small letter and after that each word starts with a capital letter. Pascal Case (PascalCase): In this the first letter of every word is in capital letter.

What is an example of camelCase?

Meaning of camel case in English. the use of a capital letter to begin the second word in a compound name or phrase, when it is not separated from the first word by a space: Examples of camel case include "iPod" and "GaGa." Want to learn more?


1 Answers

camelCase:

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

PascalCase:

^[A-Z][a-z]+(?:[A-Z][a-z]+)*$
like image 90
Alix Axel Avatar answered Oct 24 '22 13:10

Alix Axel