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
Related patterns
Python Package Name (PEP 508)
IdentifiersValidate Python distribution package names per PEP 508: letters, digits, dots, underscores, hyphens.
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Kubernetes Pod Name (RFC 1123)
IdentifiersValidate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
Kubernetes Label (key=value)
IdentifiersValidate Kubernetes label `key=value` pairs per the K8s naming spec.