There is no official RFC or standard on Camel Case or Pascal Case. This document attempts to fill that void.
Below we provide tested regular expressions for the various variations of camel case and pascal case.
Camel Case can be broken down into:
- Lower Camel Case, also known as Camel Case, starts with a lower case alphabet
- Upper Camel Case, also known as Pascal Case, starts with an upper case alphabet
Common rules:
- Camel case words MUST start with a lower case alphabet or an upper case alphabet
- Camel case words CAN AT MOST have one capital letter in a row. Note: some implementations allow for more than one upper case alphabet in a row, to support capitalized acronyms such as
IOStream
,StreamIO
,DeviceID
,deviceID
,AwsVPC
,awsVPC
,serialNO
,SerialNO
,deviceSN
,DeviceSN
. This variation is documented in Microsoft's Capitalization Convention. - Camel case words MUST HAVE no Spaces, punctuation, underscores, dots and special characters.
- Camel case words MAY have all lower case alphabets.
- Camel case words MAY end in an upper case alphabet.
- Camel case words MAY contain numbers (depending on the implementation/usecases)
- Camel Case - No Digits Allowed
- Camel Case - Digits Allowed
- Camel Case - No Digits Allowed - Upto 3 upper case letters
- Camel Case - Digits Allowed - Upto 3 upper case letters
- Pascal Case - No Digits Allowed
- Pascal Case - Digits Allowed
- Pascal Case - No Digits Allowed - Upto 3 upper case letters
- Pascal Case - Digits Allowed - Upto 3 upper case letters
To be proper camel case a word with no digits allowed:
- MUST start with a lower case alphabet (a through z)
- MUST have no digits (0 - 9)
- MUST have no spaces, punctuation or special characters
- CAN have at most 1 uppercase alphabet in a row
- MAY end in an uppercase alphabet
^[a-z][a-z]*(([A-Z][a-z]+)*[A-Z]?|([a-z]+[A-Z])*|[A-Z])$
- Regex 101 library entry: https://regex101.com/library/4h7A1I
a
is valid lower camel caseaG
is valid lower camel casecamelCase
is valid lower camel casecamelCasE
is valid lower camel caseaGa
is valid lower camel casealphabet
is valid lower camel casecamelCase
is valid lower camel case
To be proper camel case a word with digits allowed:
- MUST start with a lower case alphabet (a through z)
- MUST have no spaces, punctuation or special characters
- CAN have at most 1 uppercase alphabet in a row
- MAY end in an uppercase alphabet
- MAY contain digits 0 - 9
^[a-z][a-z0-9]*(([A-Z][a-z0-9]+)*[A-Z]?|([a-z0-9]+[A-Z])*|[A-Z])$
- Regex 101 library entry: https://regex101.com/library/8nQras
cP3
is valid lower camel case (with digits allowed)a1
is valid lower camel case (with digits allowed)a1G
is valid lower camel case (with digits allowed)a123
is valid lower camel case (with digits allowed)camelCa1
is valid lower camel case (with digits allowed)camel01C
is valid lower camel case (with digits allowed)
To be proper camel case a word with no digits allowed and upto 3 upper case letters:
- Must start with a lower case alphabet (a through z)
- Must have no digits (0 - 9)
- MUST have no spaces, punctuation or special characters
- Can have at most 3 uppercase alphabets in a row
- Can end in an uppercase alphabet
This variation is used to support phrases like deviceID
, serialNO
, streamIO
, awsVPC
, deviceSN
.
^[a-z][a-z]*(([A-Z]{1,3}[a-z]+)*[A-Z]{0,3}|([a-z]+[A-Z]{1,3})*|[A-Z]{1,3})$
Regex 101 library entry: https://regex101.com/library/bn3PEK
streamIO
is valid lower camel case with no digits allowed - Upto 3 upper case lettersdeviceID
is valid lower camel case with no digits allowed - Upto 3 upper case lettersserialNO
is valid lower camel case with no digits allowed - Upto 3 upper case lettersawsVPC
is valid lower camel case with no digits allowed - Upto 3 upper case letters
To be proper camel case a word with digits allowed and upto 3 upper case letters:
- MUST start with a lower case alphabet (a through z)
- MUST have no spaces, punctuation or special characters
- CAN have at most 3 uppercase alphabets in a row
- CAN end in an uppercase alphabet
- MAY contain digits 0 - 9
This variation is used to support phrases like deviceID
, serialNO
, streamIO
, awsVPC
, deviceSN
.
^[a-z][a-z0-9]*(([A-Z]{1,3}[a-z0-9]+)*[A-Z]{0,3}|([a-z0-9]+[A-Z]{1,3})*|[A-Z]{1,3})$
Regex 101 library entry: https://regex101.com/library/C2eHyc
camel01CC01
is valid lower camel case, with digits allowed, with upto 3 upper case letters
To be proper pascal case with no digits allowed, a word:
- MUST start with an upper case alphabet (A through Z)
- MUST have no digits (0 - 9)
- MUST have no spaces, punctuation or special characters
- CAN have at most 1 uppercase alphabet in a row
- CAN end in an uppercase alphabet
^[A-Z](([a-z]+[A-Z]?)*)$
Regex 101 library entry: https://regex101.com/library/sF2jRZ
A
is valid pascal caseAg
is valid pascal caseAaA
is valid pascal case
To be proper pascal case a word with digits allowed and with upto 3 upper case letters:
- MUST start with an upper case alphabet (A through Z)
- MUST have no spaces, punctuation or special characters
- CAN have at most 1 uppercase alphabet in a row
- CAN end in an uppercase alphabet
- MAY contain digits 0 - 9
^[A-Z](([a-z0-9]+[A-Z]?)*)$
Regex 101 library entry: https://regex101.com/library/csrkQw
Aabc123
is valid pascal case with digits allowedPascal2Case
is valid pascal case with digits allowedPascal2CaseA
is valid pascal case with digits allowedMode2A
is valid pascal case with digits allowedMode2A2
is valid pascal case with digits allowedMode2A2A
is valid pascal case with digits allowedSupportsIpv6OnIos
is valid pascal case with digits allowed
To be proper pascal case a word with no digits allowed and with upto 3 upper case letters:
- MUST start with an upper case alphabet (A through Z)
- MUST have no digits (0 - 9)
- MUST have no spaces, punctuation or special characters
- CAN have at most 3 uppercase alphabets in a row
- CAN end in an uppercase alphabet
This variation is used to support phrases like DeviceID
, DeviceSN
, StreamIO
, IOStream
, AwsVPC
, SerialNO
.
^[A-Z](([A-Z]{1,2}[a-z]+)+([A-Z]{1,3}[a-z]+)*[A-Z]{0,3}|([a-z]+[A-Z]{0,3})*|[A-Z]{1,2})$
Regex 101 library entry: https://regex101.com/library/0HyUw3
IOStream
is valid pascal case with no digits allowed and with upto 3 upper case lettersStreamIO
is valid pascal case with no digits allowed and with upto 3 upper case lettersIOStream
is valid pascal case with no digits allowed and with upto 3 upper case lettersDeviceID
is valid pascal case with no digits allowed and with upto 3 upper case lettersAwsVPC
is valid pascal case with no digits allowed and with upto 3 upper case lettersDeviceSNS
is valid pascal case with no digits allowed and with upto 3 upper case lettersCreateAMode
is valid pascal case with no digits allowed and with upto 3 upper case lettersCreateBMode
is valid pascal case with no digits allowed and with upto 3 upper case lettersABCabcABCabc
is valid pascal case with no digits allowed and with upto 3 upper case lettersABCabcABCabcA
is valid pascal case with no digits allowed and with upto 3 upper case letters
To be proper pascal case a word with digits allowed and with upto 3 upper case letters:
- MUST start with an upper case alphabet (A through Z)
- MUST have no spaces, punctuation or special characters
- CAN have at most 3 uppercase alphabets in a row
- CAN end in an uppercase alphabet
- MAY contain digits 0 - 9
This variation is used to support phrases like DeviceID
, DeviceSN
, StreamIO
, IOStream
, AwsVPC
, SerialNO
.
^[A-Z](([A-Z]{1,2}[a-z0-9]+)+([A-Z]{1,3}[a-z0-9]+)*[A-Z]{0,3}|([a-z0-9]+[A-Z]{0,3})*|[A-Z]{1,2})$
Regex 101 library entry: https://regex101.com/library/TLTXbK
Camel01CC01
is valid pascal case with digits allowed and with upto 3 upper case letters
All the test case phrases are in the phrases folder. To run the tests run the following command in a cloned repo:
npm install
npm test