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
.
Name | Formatting | Glob Pattern | RegExp |
---|---|---|---|
CAMEL_CASE | helloWorld | +([a-z])*([A-Z]*([a-z0-9])) | /^([a-z]+){1}([A-Z][a-z0-9]*)*$/ |
PASCAL_CASE | HelloWorld | *([A-Z]*([a-z0-9])) | /^([A-Z][a-z0-9]*)*$/ |
SNAKE_CASE | hello_world | +([a-z])*(_+([a-z0-9])) | /^([a-z]+_?)([a-z0-9]+_)*[a-z0-9]+$/ |
KEBAB_CASE | hello-world | +([a-z])*(-+([a-z0-9])) | /^([a-z]+-?)([a-z0-9]+-)*[a-z0-9]+$/ |
SCREAMING_SNAKE_CASE | HELLO_WORLD | +([A-Z])*(_+([A-Z0-9])) | /^([A-Z]+_?)([A-Z0-9]+_)*[A-Z0-9]+$/ |
FLAT_CASE | helloworld | +([a-z0-9]) | /^[a-z0-9]+$/ |