Identifiers
npm Package Name
Validate npm package names including scoped packages (@org/package), per the npm naming spec.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$Raw source: ^(?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$
How it works
The optional group (?:@[a-z0-9\-*~][a-z0-9\-*._~]*\/)? matches a @scope/ prefix for scoped packages. The main name [a-z0-9\-~][a-z0-9\-._~]* matches lowercase letters, digits, hyphens, dots, and tildes. Uppercase is not allowed per npm rules.
Examples
Input
reactMatches
react
Input
@types/nodeMatches
@types/node
Input
MyPackageNo match
—Common use cases
- •package.json validation in monorepo tooling
- •Custom registry name enforcement
- •Automated dependency auditing scripts
- •CLI tools that accept package names as arguments