Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^[a-z][a-z]*(([A-Z][a-z]+)*[A-Z]?|([a-z]+[A-Z])*|[A-Z])$
/
gm

Description

To be proper camel case a word with no digits allowed, a word:

  • 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

Notable examples

  • a is valid lower camel case
  • aG is valid lower camel case
  • camelCase is valid lower camel case
  • camelCasE is valid lower camel case
  • aGa is valid lower camel case
  • alphabet is valid lower camel case
Submitted by roubles - 2 years ago (Last modified 2 years ago)