Regex, which is in line with the case of Camel and Pascal

I am going to write a parser for a language that must have strict syntax rules about type names, variables, etc. For example, all classes must be PascalCase, and all variable / parameter names and other identifiers must be camelCase.

For example, it is HTMLParsernot permitted and should be specified HTMLParser. Any ideas for regex that might match what PascalCase is, but don't have two capital letters in it?

+3
source share
3 answers

camel:

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

PascalCase:

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

, , HTMLParser .

+2

, (, -, ), - ( )

/([A-Z][a-z0-9]+)*[A-Z][a-z0-9]*/

- : " ", , , , , .

.

+1

Source: https://habr.com/ru/post/1729263/


All Articles