Using Glob Patterns to Match Common Naming Conventions

Glob patterns are commonly used to match filenames, and they are simpler and easier to understand than regular expressions. It also can match arbitrary strings. We will use glob patterns to match 6 common naming conventions in this article, including CAMEL_CASE, PASCAL_CASE, SNAKE_CASE, KEBAB_CASE, SCREAMING_SNAKE_CASE and FLAT_CASE.

NameFormattingGlob PatternRegExp
CAMEL_CASEhelloWorld+([a-z])*([A-Z]*([a-z0-9]))/^([a-z]+){1}([A-Z][a-z0-9]*)*$/
PASCAL_CASEHelloWorld*([A-Z]*([a-z0-9]))/^([A-Z][a-z0-9]*)*$/
SNAKE_CASEhello_world+([a-z])*(_+([a-z0-9]))/^([a-z]+_?)([a-z0-9]+_)*[a-z0-9]+$/
KEBAB_CASEhello-world+([a-z])*(-+([a-z0-9]))/^([a-z]+-?)([a-z0-9]+-)*[a-z0-9]+$/
SCREAMING_SNAKE_CASEHELLO_WORLD+([A-Z])*(_+([A-Z0-9]))/^([A-Z]+_?)([A-Z0-9]+_)*[A-Z0-9]+$/
FLAT_CASEhelloworld+([a-z0-9])/^[a-z0-9]+$/