Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
\b (?!\p{Lu}+\b) # CaMeL can't be an ALLCAPS (remove to allow) (?=\p{L}*\p{Ll}) # CaMeL word should have at least 1 lowercase letter (?=\p{L}*\p{Lu}) # CaMeL word should have at least 1 uppercase letter (?!\p{Lu}\p{Ll}*\b) # CaMeL word can't be `Xxxx` or `X` \p{L}+ # CaMeL word should contain at least 1 letter \b
/
gx

Description

The PCRE (or any regex flavor supporting word boundaries, Unicode properties and lookaheads) \b(?!\p{Lu}+\b)(?=\p{L}\p{Ll})(?=\p{L}\p{Lu})(?!\p{Lu}\p{Ll}*\b)\p{L}+\b regex finds CaMeL words that:

  • Have at least 1 lowercase letter
  • Have at least 1 uppercase letter
  • Do not follow the X, XXX or Xxxx patterns

Author's SO profile: http://stackoverflow.com/users/3832970/wiktor-stribi%C5%BCew

Submitted by Wiktor Stribiżew - 9 years ago