Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

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

Description

To be proper camel case (with digits allowed) a word:

  • 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

Notable examples

  • 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)
Submitted by roubles - 2 years ago